PDF转换成Word,ppt转换成word
pdf与word我没找到直接转换的方式,不过可以用间接方式嘛!
pdf ==》picture ==》word!ppt转word的原理也是先把ppt转成图片,再把图片插入word!
先准备好几个程序集:fontbox-0.1.0-dev.dll,IKVM.GNU.Classpath.dll,IKVM.Runtime.dll,Interop.Microsoft.Office.Core.dll,PDFBox-0.7.3.dll,Spire.Doc.dll,Spire.License.dll,Spire.Pdf.dll
一个小工具:gswin32.exe
pdf转word主要代码:
/// <summary>
/// 将PDF文档转换成图片
/// </summary>
/// <param name="pdfFile">PDF文档物理路径</param>
/// <param name="imgPath">转换成的图片文件的存放物理路径</param>
/// <param name="isDeletePDF">转换成图片文件以后是否删除原PDF文档</param>
/// <returns>返回转换成的图片文件物理路径的集合</returns>
public List<string> PdfToImages(string pdfFile, string imgPath, bool isDeletePDF)
{
List<string> imgList = new List<string>(); PDDocument doc = PDDocument.load(pdfFile); int pageCount = doc.getDocumentCatalog().getAllPages().size();//计算pdf文档的总页数 string pdfFileName = Path.GetFileName("");
int index = pdfFileName.LastIndexOf('.');
if (index != -)
pdfFileName = pdfFileName.Substring(, index); string imgFile = Path.Combine(imgPath, pdfFileName);//转换成的图片文件 if (pageCount == ) return null;
if (pageCount == )
{
imgFile += ".jpg";
imgList.Add(imgFile);
if (File.Exists(imgFile)) File.Delete(imgFile);
}
else
{
for (int i = ; i < pageCount; i++)
{
string _imgFile = imgFile + (i + ).ToString() + ".jpg";
imgList.Add(_imgFile);
if (File.Exists(_imgFile)) File.Delete(_imgFile);
}
imgFile += "%d.jpg";
}
//此调用方法有命令框出现
// System.Diagnostics.Process.Start(System.Configuration.ConfigurationManager.AppSettings["GhostScriptView"] +"\\gswin32.exe", System.Configuration.ConfigurationManager.AppSettings["GhostScriptArguments"] + @" -sOutputFile=" + imgFile + " " + pdfFile); ProcessStartInfo startinfo = new ProcessStartInfo();
startinfo.CreateNoWindow = true;
startinfo.FileName = System.Configuration.ConfigurationManager.AppSettings["GhostScriptView"] + "\\gswin32.exe";
startinfo.Arguments = System.Configuration.ConfigurationManager.AppSettings["GhostScriptArguments"] + @" -sOutputFile=" + imgFile + " " + pdfFile;
startinfo.WindowStyle = ProcessWindowStyle.Hidden;
startinfo.CreateNoWindow = true;
startinfo.UseShellExecute = true;
Process p = new Process();
p.StartInfo = startinfo;
p.Start();
if (p.WaitForExit(**))
{
Thread.Sleep();
p.Close();
} if (isDeletePDF)
{
File.Delete(pdfFile);
} return imgList;
}
/// <summary>
/// 图片插入word
/// </summary>
/// <param name="ImagesURL">图片路径集合</param>
public void PicToWord(List<string> ImagesURL)
{
//Thread.Sleep(1000);
//Process[] thepro = Process.GetProcessesByName("gswin32");
//if (thepro.Length > 0)
////如果进程曾在或者不止一个
//{
// //逐个结束
// for (int i = 0; i < thepro.Length; i++)
// {
// //如果还没有结束就关闭他
// if (!thepro[i].CloseMainWindow()) thepro[i].Kill();
// }
//} for (int i = ; i < ImagesURL.Count; i++)
{
if (File.Exists(ImagesURL[i].ToString() + ".jpg"))
{
File.Delete(ImagesURL[i].ToString() + ".jpg");
}
if (File.Exists(ImagesURL[i].ToString()))
{
File.Copy(ImagesURL[i].ToString(), ImagesURL[i].ToString() + ".jpg");
}
}
//ThreadPool.QueueUserWorkItem( //使用线程池
//(P_temp) => //使用lambda表达式
//{
word.Application newapp = new word.Application(); //创建Word应用程序对象
object nothing = System.Reflection.Missing.Value;
word.Document newdoc = newapp.Documents.Add(ref nothing, ref nothing, ref nothing, ref nothing);//生成一个word文档
if (newdoc != null)
{
try
{
for (int i = (ImagesURL.Count - ); i >= ; i--)
{
string a = ImagesURL[i].ToString() + ".jpg";
newdoc.InlineShapes.AddPicture(a);
File.Delete(ImagesURL[i].ToString());
File.Delete(ImagesURL[i].ToString() + ".jpg");
} }
catch (Exception ex)
{
this.TextBox1.Text = ex.Message;
} // newdoc.Close();
newdoc.SaveAs("F:\\Test.docx");
newapp.Quit();
}
// });
}
ppt转word主要代码:
/// <summary>
/// PPT转Word
/// </summary>
/// <param name="pptPath">ppt文件路径</param>
/// <param name="imgPath">图片路径</param>
/// <param name="WordPath">存放word文档路径</param>
/// <returns></returns>
public bool PPTToWord(string pptPath,string imgPath,string WordPath)
{
bool bo=true;
List<string> image = new List<string>();
try
{
var app = new PowerPoint.Application();
var ppt = app.Presentations.Open(pptPath, Core.MsoTriState.msoFalse, Core.MsoTriState.msoFalse, Core.MsoTriState.msoFalse);
var index = ;
var fileName = System.IO.Path.GetFileNameWithoutExtension(pptPath);
foreach (PowerPoint.Slide slid in ppt.Slides)
{
++index;
//设置图片大小
slid.Export(imgPath + string.Format("page{0}.png", index.ToString()), "png", , );
image.Add(imgPath + string.Format("page{0}.png", index.ToString()));
}
//释放资源
ppt.Close();
app.Quit();
GC.Collect();
}
catch (Exception ex)
{
bo = false ;
} Word.Application newapp = new Word.Application(); //创建Word应用程序对象
object nothing = System.Reflection.Missing.Value;
Word.Document newdoc = newapp.Documents.Add(ref nothing, ref nothing, ref nothing, ref nothing);//生成一个word文档
if (newdoc != null)
{
try
{
for (int i = (image.Count - ); i >= ; i--)
{
string a = image[i].ToString();
newdoc.InlineShapes.AddPicture(a);
File.Delete(image[i].ToString());
}
}
catch (Exception ex)
{
bo = false;
}
newdoc.SaveAs(WordPath);
newapp.Quit();
}
return bo;
}
这就ok了!
但是!当小女子放到服务器(win2008)上发现,天呐!bug!bug!bug!pdf能转成图片,但是在插入图片的时候报错,未将对象引用到实例!再看看ppt转word。Oh my god!ppt不能open!
奇怪,在我的电脑上没问题呀,这是怎么回事呢!仔细看看规律。pdf与office不是同一回事,出问题的都是office!抱着试试的心态,给office赋予权限去!
comexp.msc -32,打开32位的组件服务。"组件服务"->"计算机"->"我的电脑"->"DCOM配置"。找到office,给每一个office配置都赋予权限。
1、右键==》属性==》安全==》启动和激活权限==》自定义==》编辑==》添加Everyone==》本地启动、本地激活。
2、右键==》属性==》安全==》访问权限==》自定义==》编辑==》添加Everyone==》本地访问。
3、右键==》属性==》安全==》配置权限==》自定义==》编辑==》添加Everyone==》完全控制。
4、右键==》属性==》标识==》交互使用户。
看看我们的程序,这个时候已经完全成功了!!!!
PDF转换成Word,ppt转换成word的更多相关文章
- word ppt excel文档转换成pdf
1.把word文档转换成pdf (1).添加引用 using Microsoft.Office.Interop.Word; 添加引用 (2).转换方法 /// <summary> /// ...
- C#.net word excel powerpoint (ppt) 转换成 pdf 文件
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- Java通过openOffice实现word,excel,ppt转成pdf实现在线预览
Java通过openOffice实现word,excel,ppt转成pdf实现在线预览 一.OpenOffice 1.1 下载地址 1.2 JodConverter 1.3 新建实体类PDFDemo ...
- 如何将WORD表格转换成EXCEL表格
WORD和EXCEL都可以制作表格,但WORD表格与EXCEL表格之间有着很明显的差距,所以在办公中经常会需要将WORD转换成EXCEL,今天小编就教大家一招将WORD表格转换成EXCEL表格. 操作 ...
- 用Python将word文件转换成html(转)
用Python将word文件转换成html 序 最近公司一个客户大大购买了一堆医疗健康方面的科普文章,希望能放到我们正在开发的健康档案管理软件上.客户大大说,要智能推送!要掌握节奏!要深度学习!要 ...
- python如何转换word格式、读取word内容、转成html
# python如何转换word格式.读取word内容.转成html? import docx from win32com import client as wc # 首先将doc转换成docx wo ...
- c# 将PPT转换成HTML
这只是一个小程序,就是将ppt转换成html,方法很多,为了以后备用,在此记录一下,也和大家分享 源码如下: using System; using System.Collections.Generi ...
- 杂项-PPT:如何把幻灯片ppt转换成视频
ylbtech-杂项-PPT:如何把幻灯片ppt转换成视频 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 1. https://jingyan.baidu.co ...
- java 将word转为PDF (100%与word软件转换一样)
jdk环境:jdk_8.0.1310.11_64 (64位) 1.引入pom文件 <!-- word转pdf(依赖windows本地的wps) --> <dependency& ...
随机推荐
- 【easy】108. Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Fo ...
- LNMP安装目录及配置文件位置
LNMP相关软件安装目录 Nginx 目录: /usr/local/nginx/ MySQL 目录 : /usr/local/mysql/MySQL数据库所在目录:/usr/local/mysql/v ...
- ogg 单表拆分合并进程
metalink文档:1320133.1和1512633.1 map scott.emp1, target scott.emp1 ,FILTER(@RANGE(1,3)); --拆分 map sco ...
- python学习第37天
MySQL数据库 数据库的优势 什么是数据(Data) 什么是数据库(DataBase,简称DB) 什么是数据库管理系统(DataBase Managerment System 简称DBMS) 数据库 ...
- Git客户端(TortoiseGit)基本使用详解
1. 环境安装 Git最新版下载地址:https://gitforwindows.org/ TortoiseGit,Git客户端,32/64位最新版及对应的语言包下载地址:https://tortoi ...
- 【mysql】 快速搞定数据库迁移
工具:navicat for mysql
- Lesson 2-2(列表,元组)
2.3 列表 2.3.1 列表的创建方法 --- 使用方括号 [] ,括号中的元素之间使用逗号隔开. >>> [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] > ...
- Joone
JOONE 一.什么是JOONE? 1.Joone是一个免费的神经网络框架来创建,训练和测试人造神经网络.目标是为最热门的Java技术创造一个强大的环境,为热情和专业的用户.2.Joone由一个中央引 ...
- urls控制器
路由分发include('blog.urls')): 将以指定名称开头的url分发到指定app中去匹配 urlpatterns = [ url(r'^admin/', admin.site.urls) ...
- Unity 5.x动态加载光照信息(所有坑已踩)
能搜到这的应该是被新的烘焙系统坑了少时间,4.x到5.x美术必须重新烘焙,关于美术的没什么说的,只有---重新烘焙! 新的烘焙系统,为了兼容5.x的多场景编辑功能,将烘焙信息从mesh全部挪到了一个中 ...