架构师_程序员_码农网

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

搜索
查看: 25492|回复: 0

[资料] Microsoft.Office.Interop.Word把word文档转换成pdf

[复制链接]
发表于 2016-4-6 23:15:24 | 显示全部楼层 |阅读模式
  1. //// <summary>
  2.     /// 把Word文件转换成pdf文件
  3.     /// </summary>
  4.     /// <param name="sourcePath">需要转换的文件路径和文件名称</param>
  5.     /// <param name="targetPath">转换完成后的文件的路径和文件名名称</param>
  6.     /// <returns>成功返回true,失败返回false</returns>
  7.     public static bool WordToPdf(object sourcePath, string targetPath)
  8.     {
  9.         bool result = false;
  10.         WdExportFormat wdExportFormatPDF = WdExportFormat.wdExportFormatPDF;
  11.         object missing = Type.Missing;
  12.         Microsoft.Office.Interop.Word.ApplicationClass applicationClass = null;
  13.         Document document = null;
  14.         try
  15.         {
  16.             applicationClass = new Microsoft.Office.Interop.Word.ApplicationClass();
  17.             document = applicationClass.Documents.Open(ref sourcePath, 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);
  18.             if (document != null)
  19.             {
  20.                 document.ExportAsFixedFormat(targetPath, wdExportFormatPDF, false, WdExportOptimizeFor.wdExportOptimizeForPrint, WdExportRange.wdExportAllDocument, 0, 0, WdExportItem.wdExportDocumentContent, true, true, WdExportCreateBookmarks.wdExportCreateWordBookmarks, true, true, false, ref missing);
  21.             }
  22.             result = true;
  23.         }
  24.         catch
  25.         {
  26.             result = false;
  27.         }
  28.         finally
  29.         {
  30.             if (document != null)
  31.             {
  32.                 document.Close(ref missing, ref missing, ref missing);
  33.                 document = null;
  34.             }
  35.             if (applicationClass != null)
  36.             {
  37.                 applicationClass.Quit(ref missing, ref missing, ref missing);
  38.                 applicationClass = null;
  39.             }
  40.         }
  41.         return result;
  42.     }
复制代码






上一篇:打印常识:A4纸张在显示器上应该要多少像素?
下一篇:itextsharp生成PDF的一个开源组件
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

免责声明:
码农网所发布的一切软件、编程资料或者文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:help@itsvse.com

QQ|小黑屋|架构师 ( 鲁ICP备14021824号-2 )|网站地图

GMT+8, 2026-4-12 19:57

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表