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、右键==》属性==》标识==》交互使用户。

看看我们的程序,这个时候已经完全成功了!!!!

程序集与gswin32下载

PDF转换成Word,ppt转换成word的更多相关文章

  1. word ppt excel文档转换成pdf

    1.把word文档转换成pdf (1).添加引用 using Microsoft.Office.Interop.Word; 添加引用 (2).转换方法 /// <summary> /// ...

  2. C#.net word excel powerpoint (ppt) 转换成 pdf 文件

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  3. Java通过openOffice实现word,excel,ppt转成pdf实现在线预览

    Java通过openOffice实现word,excel,ppt转成pdf实现在线预览 一.OpenOffice 1.1 下载地址 1.2 JodConverter 1.3 新建实体类PDFDemo ...

  4. 如何将WORD表格转换成EXCEL表格

    WORD和EXCEL都可以制作表格,但WORD表格与EXCEL表格之间有着很明显的差距,所以在办公中经常会需要将WORD转换成EXCEL,今天小编就教大家一招将WORD表格转换成EXCEL表格. 操作 ...

  5. 用Python将word文件转换成html(转)

    用Python将word文件转换成html   序 最近公司一个客户大大购买了一堆医疗健康方面的科普文章,希望能放到我们正在开发的健康档案管理软件上.客户大大说,要智能推送!要掌握节奏!要深度学习!要 ...

  6. python如何转换word格式、读取word内容、转成html

    # python如何转换word格式.读取word内容.转成html? import docx from win32com import client as wc # 首先将doc转换成docx wo ...

  7. c# 将PPT转换成HTML

    这只是一个小程序,就是将ppt转换成html,方法很多,为了以后备用,在此记录一下,也和大家分享 源码如下: using System; using System.Collections.Generi ...

  8. 杂项-PPT:如何把幻灯片ppt转换成视频

    ylbtech-杂项-PPT:如何把幻灯片ppt转换成视频 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 1. https://jingyan.baidu.co ...

  9. java 将word转为PDF (100%与word软件转换一样)

    jdk环境:jdk_8.0.1310.11_64    (64位) 1.引入pom文件 <!-- word转pdf(依赖windows本地的wps) --> <dependency& ...

随机推荐

  1. java程序员技术范围

    1 工具 开发工具.源代码管理.构建工具.测试工具(压力.安全等).接口测试工具.反编译工具.日志工具.第三方工具等 2 java jvm.多线程.socket.io(两种方式).集合(两大接口).异 ...

  2. 【C++11】unoedered_map和map(部分转载)

    1.结论 新版的hash_map都是unordered_map了,这里只说unordered_map和map. 运行效率:unordered_map最高,而map效率较低但提供了稳定效率和有序的序列. ...

  3. dml并行

    Enabling Parallel DMLA DML statement can be parallelized only if you have explicitly enabled paralle ...

  4. IE8引用jQuery报$或者jQuery未定义

    最近公司做的项目要求兼容到IE8,结果在页面调试的时候出了个bug,在IE8上面一直报错$未定义,或者jQuery未定义,导致页面上面写的jQuery全部失效,在Chrome浏览器没有任何问题.很是头 ...

  5. 论文阅读笔记四十七:Generalized Intersection over Union: A Metric and A Loss for Bounding Box Regression(CVPR2019)

    论文原址:https://arxiv.org/pdf/1902.09630.pdf github:https://github.com/generalized-iou 摘要 在目标检测的评测体系中,I ...

  6. 初探storm

    Storm入门之Storm示例及UI参数讲解 Storm UI REST API Storm 1.1.0 中文文档 Apache Storm 1.1.0 中文文档 | ApacheCN Storm U ...

  7. C# 模拟键盘操作SendKey(),SendKeys()

    模拟键盘输入就是使用以下2个语法实现的. SendKeys.Send(string keys);  //模拟汉字(文本)输入SendKeys.SendWait(string keys); //模拟按键 ...

  8. 为什么要使用getters和setters/访问器?

    Why use getters and setters/accessors? 实际上会有很多人问这个问题....尤其是它成为Coding Style中一部分的时候. 文章出自LBushkin的回答 T ...

  9. 连接数据库出现java.sql.SQLException: Unknown system variable 'tx_isolation'

    问题分析 :mysql-connector-java的版本太低,数据库的版本太高 因此将mysql-connector-java升级到最新版本就解  .或者降低MySQL的版本.我之前用的是8.0版本 ...

  10. Motrix for Mac(百度网盘加速/全能下载软件) v1.3.7最新版!

    Motrix for Mac最新版第一时间在本站上线!Mac上最强大实用百度网盘加速器Motrix for Mac分享给您!Motrix for Mac是一款非常优秀的下载工具,采用Aria 2作为核 ...