C#中word转pdf代码
来源:互联网 发布:ubuntu16.04安装mysql 编辑:程序博客网 时间:2024/06/01 09:26
/// <summary> /// 把Word文件转换成pdf文件 /// </summary> /// <param name="sourcePath">需要转换的文件路径和文件名称</param> /// <param name="targetPath">转换完成后的文件的路径和文件名名称</param> /// <returns>成功返回true,失败返回false</returns> public static bool WordToPdf(string sourcePath, string targetPath) { bool result = false; WdExportFormat wdExportFormatPDF = WdExportFormat.wdExportFormatPDF;//转换格式1.wdExportFormatPDF转换成pdf格式 2.wdExportFormatXPS转换成xps格式 object missing = Type.Missing; Microsoft.Office.Interop.Word.ApplicationClass applicationClass = null; Document document = null; try { applicationClass = new Microsoft.Office.Interop.Word.ApplicationClass(); object inputfileName = sourcePath;//需要转格式的文件路径 string outputFileName = targetPath;//转换完成后PDF或XPS文件的路径和文件名名称 WdExportFormat exportFormat = wdExportFormatPDF;//导出文件所使用的格式 bool openAfterExport = false;//转换完成后是否打开 WdExportOptimizeFor wdExportOptimizeForPrint = WdExportOptimizeFor.wdExportOptimizeForPrint;//导出方式1.wdExportOptimizeForPrint针对打印进行导出,质量较高,生成的文件大小较大。2.wdExportOptimizeForOnScreen 针对屏幕显示进行导出,质量较差,生成的文件大小较小。 WdExportRange wdExportAllDocument = WdExportRange.wdExportAllDocument;//导出全部内容(枚举) int from = 0;//起始页码 int to = 0;//结束页码 WdExportItem wdExportDocumentContent = WdExportItem.wdExportDocumentContent;//指定导出过程中是否只包含文本或包含文本的标记.1.wdExportDocumentContent:导出文件没有标记,2.导出文件有标记 bool includeDocProps = true;//指定是否包含新导出的文件在文档属性 bool keepIRM = true;// WdExportCreateBookmarks wdExportCreateWordBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks;//1.wdExportCreateNoBookmarks:不要在导出文件中创建书签,2.wdExportCreateHeadingBookmarks:标题和文本框导出的文件中创建一个书签,3.wdExportCreateWordBookmarks每个字的书签,其中包括除包含页眉和页脚中的所有书签导出的文件中创建一个书签。 bool docStructureTags = true; bool bitmapMissingFonts = true; bool UseISO19005_1 = false;//生成的文档是否符合 ISO 19005-1 (PDF/A) document = applicationClass.Documents.Open(ref inputfileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); if (document != null) { document.ExportAsFixedFormat(outputFileName, exportFormat, openAfterExport, wdExportOptimizeForPrint, wdExportAllDocument, from, to, wdExportDocumentContent, includeDocProps, keepIRM, wdExportCreateWordBookmarks, docStructureTags, bitmapMissingFonts, UseISO19005_1, ref missing); } else { foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName("WINWORD")) { p.Kill(); } } result = true; } catch (Exception ex) { ExceptionManagement.ExceptionManage.ExceptionHandle(ex); result = false; } finally { if (document != null) { document.Close(ref missing, ref missing, ref missing); document = null; } if (applicationClass != null) { applicationClass.Quit(ref missing, ref missing, ref missing); applicationClass = null; } } return result; }
阅读全文
0 0
- C#中word转pdf代码
- C# word转pdf
- c# word转PDF
- word转pdf代码
- C#实现Word转PDF
- C# 实现Excel转Word、Word转PDF、合并PDF
- C# Word文档转PDF的实现
- C# Word文档转PDF的实现
- c# word ppt excel转pdf
- c# word ppt excel转pdf
- PHP处理Word转PDF代码示例
- java代码实现word转PDF
- c# html代码转pdf
- c# word批量转换pdf
- C#利用word2007插件实现word转pdf
- 利用Minidx Extract-Text Com组件从Word,Xls,Pdf……等文件中读取 后附C# 调用代码
- C#使用指定打印机打印Word,Excel等Office文件和打印PDF文件的代码
- word转pdf
- 动态代理与AOP(2)
- Android设置ListView的分割线长度
- 我是怎么阅读kubernetes源代码的?
- 2.idea下springboot项目的热部署
- 百度音乐API抓取
- C#中word转pdf代码
- Exception in thread "http-apr-8080-exec-6" java.lang.OutOfMemoryError: PermGen space 解决!
- 11、Selenium + Python 实现 UI 自动化测试-操作按钮、复选框
- h5新增标签(部分)
- ntpdate
- proc_day1
- Touch Feedback(触摸反馈):水波纹
- Hibernate环境搭建
- 淘宝评论爬虫python