C#将word文档转为PDF |
您所在的位置:网站首页 › npoi导出pdf › C#将word文档转为PDF |
最近接到的工作 1.word转PDF 2.PDF添加水印,并控制显示的页数 3.JPG转PDF
使用 Microsoft.Office.Interop.Word 将word文档转为PDF
在NuGet中搜索 Microsoft.Office.Interop.Word 安装
方法 参数参考 微软官网地址
/// /// 将word转成PDF office /// /// /// /// public static bool WordToPDFWithOffice(string sourcePath, string targetPath, int fromPage = 1, int toPage = 1) { bool result = false; Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application(); Document document = null; try { application.Visible = false; document = application.Documents.Open(sourcePath); /* 参数参考 https://docs.microsoft.com/zh-cn/office/vba/api/visio.document.exportasfixedformat */ document.ExportAsFixedFormat(targetPath, WdExportFormat.wdExportFormatPDF, false, WdExportOptimizeFor.wdExportOptimizeForPrint, WdExportRange.wdExportFromTo, fromPage, toPage); result = true; } catch (Exception e) { //Console.WriteLine(e.Message); result = false; } finally { document.Close(); } return result; }
本文来自博客园,作者:吃兔子的萝卜7,转载请注明原文链接:https://www.cnblogs.com/kangsir7/p/15724559.html |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |