最近用到一个功能word转pdf,有个方法不错,挺方便的,直接调用即可,记录下

方法:ConvertWordToPdf(string sourcePath, string targetPath)

sourcePath:word文件路径

targetPath:生成pdf文件路径

注:两个路径都为绝对路径

获取绝对路径:Server.MapPath("../zfjl/wj.docx");

  public static bool ConvertWordToPdf(string sourcePath, string targetPath)
{
Microsoft.Office.Interop.Word.WdExportFormat exportFormat;
exportFormat = Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF;
bool result;
object paramMissing = Type.Missing;
word.ApplicationClass wordApplication = new word.ApplicationClass();
word.Document wordDocument = null;
try
{
object paramSourceDocPath = sourcePath;
string paramExportFilePath = targetPath; word.WdExportFormat paramExportFormat = exportFormat;
bool paramOpenAfterExport = false;
word.WdExportOptimizeFor paramExportOptimizeFor =
word.WdExportOptimizeFor.wdExportOptimizeForPrint;
word.WdExportRange paramExportRange = word.WdExportRange.wdExportAllDocument;
int paramStartPage = ;
int paramEndPage = ;
word.WdExportItem paramExportItem = word.WdExportItem.wdExportDocumentContent;
bool paramIncludeDocProps = true;
bool paramKeepIRM = true;
word.WdExportCreateBookmarks paramCreateBookmarks =
word.WdExportCreateBookmarks.wdExportCreateWordBookmarks;
bool paramDocStructureTags = true;
bool paramBitmapMissingFonts = true;
bool paramUseISO19005_1 = false; wordDocument = wordApplication.Documents.Open(
ref paramSourceDocPath, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing); if (wordDocument != null)
wordDocument.ExportAsFixedFormat(paramExportFilePath,
paramExportFormat, paramOpenAfterExport,
paramExportOptimizeFor, paramExportRange, paramStartPage,
paramEndPage, paramExportItem, paramIncludeDocProps,
paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
paramBitmapMissingFonts, paramUseISO19005_1,
ref paramMissing);
result = true;
}
finally
{
if (wordDocument != null)
{
wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);
wordDocument = null;
}
if (wordApplication != null)
{
wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing);
wordApplication = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
return result;
}

C# word文档转换成PDF格式文档的更多相关文章

  1. C#实现文档转换成PDF

    网上有很多将doc.ppt.xls等类型的文档转换成pdf的方法,目前了解到的有两大类: 1.使用虚拟打印机将doc.ppt.xls等类型的文档 2.使用OFFICE COM组件 我采用了第二种方法实 ...

  2. ASP.NET将word文档转换成pdf的代码

    一.添加引用 using Microsoft.Office.Interop.Word; 二.转换方法 1.方法 C# 代码 /// <summary> /// 把Word文件转换成pdf文 ...

  3. word ppt excel文档转换成pdf

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

  4. JAVA:借用OpenOffice将上传的Word文档转换成Html格式

    为什么会想起来将上传的word文档转换成html格式呢?设想,如果一个系统需要发布在页面的文章都是来自word文档,一般会执行下面的流程:使用word打开文档,Ctrl+A,进入发布文章页面,Ctrl ...

  5. OpenOffice Word文档转换成Html格式

    为什么会想起来将上传的word文档转换成html格式呢?设想,如果一个系统需要发布在页面的文章都是来自word文档,一般会执行下面的流程:使用word打开文档,Ctrl+A,进入发布文章页面,Ctrl ...

  6. Linux不用使用软件把纯文本文档转换成PDF文件的方法

    当你有一大堆文本文件要维护的时候,把它们转换成PDF文档会好一些.比如,PDF更适合打印,因为PDF文档有预定义布局.除此之外,还可以减少文档被意外修改的风险. 要将文本文件转换成PDF格式,你要按照 ...

  7. 【文件】使用jacob将word转换成pdf格式

    使用jacob将word转换成pdf格式   1.需要安装word2007或以上版本,若安装07版本学确保该版本已安装2downbank0204MicrosoftSaveasPDF_ XPS,否则安装 ...

  8. java将XML文档转换成json格式数据

    功能 将xml文档转换成json格式数据 说明 依赖包:1. jdom-2.0.2.jar : xml解析工具包;2. fastjson-1.1.36.jar : 阿里巴巴研发的高性能json工具包 ...

  9. 将html版API文档转换成chm格式的API文档

    文章完全转载自: https://blog.csdn.net/u012557538/article/details/42089277 将html版API文档转换成chm格式的API文档并不是一件难事, ...

随机推荐

  1. ubuntu系统备份与恢复(也适用于其他linux系统)

    在windows环境下面,有很多的备份恢复软件,系统也自带了备份恢复功能,比较知名的软件比如ghost等,为什么要备份系统,我之前一直都是系统出现问题就全新安装原版的windows,然后各种设置,各种 ...

  2. mybatis-spring整合

    1. 配置jar包 Spring,mybatis,mybatis-spring,mysql等... <properties> <project.build.sourceEncodin ...

  3. PHP方法实现1-9数列中添加‘+’,‘-’或'',使和为100,并输出数列

    今天收到个题目:编写一个在1,2,3,4,5,6,7,8,9(顺序不能变)数字之间插入 + 或- 或什么都不插入,使得计算结果总是100的程序,并输出所有的可能性.例如 1+2+34-5+67-8+9 ...

  4. 在做APP前端开发时应注意的一些问题

    在做APP前端开发时应注意的一些问题 在整个app开发流程中,app前端开发是一个必不可少的环节,也是一个在app开发过程中重量级的角色.说到这,那么在app应用的前端开发中,又要注意什么问题呢?一. ...

  5. 使用git提交到github,每次都要输入用户名和密码的解决方法

    使用git提交文件到github,每次都要输入用户名和密码,操作起来很麻烦,以下方法可解决,记录以下. 原因:在clone 项目的时候,使用了 https方式,而不是ssh方式. 默认clone 方式 ...

  6. LNMP详解

    目录 Nginx配置    1 PHP解析    1 Mysql操作    3 服务安装    3 连接测试    3 数据配置    3 Blogs建立    4   LNMP 环境 Mysql:1 ...

  7. Microsoft AI - Custom Vision

    概述 前几天的 Windows Developer Day 正式发布了 Windows AI Platform,而作为 Windows AI Platform 的模型定义和训练,更多还是需要借助云端来 ...

  8. Mycat 分片规则详解--固定 hash 分片

    实现方式:该算法类似于十进制的求模运算,但是为二进制的操作,例如,取 id 的二进制低 10 位 与 1111111111 进行 & 运算 优点:这种策略比较灵活,可以均匀分配也可以非均匀分配 ...

  9. 排序算法Java实现(快速排序)

    算法描述:对于一组给定的记录,通过一趟排序后,将原序列分为两部分,其中前一部分的所有记录均比后一部分的所有记录小,然后再依次对前后两部分的记录进行快速排序,递归该过程,直到序列中的所有记录均有序为止. ...

  10. redis-cli的一些有趣也很有用的功能

    redis-cli我们最常用的两个参数就是-h.-p.-a选项,分配用来指定连接的redis-server的host和port. 通过redis-cli –help发现,redis-cli还提供了其他 ...