C# word格式转换为pdf
发布时间:2020-12-15 22:40:34 所属栏目:百科 来源:网络整理
导读:引用 Microsoft.Office.Interop.Word 这个dll,可以在解决方案浏览器中搜索到并下载。 源码如下: public bool WordToPDF( string sourcePath) { bool result = false ; Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Inte
引用 Microsoft.Office.Interop.Word 这个dll,可以在解决方案浏览器中搜索到并下载。 源码如下: public bool WordToPDF(string sourcePath) { bool result = false; Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word.Document document = null; try { application.Visible = false; document = application.Documents.Open(sourcePath); string PDFPath = sourcePath.Replace(".doc",".pdf");//pdf存放位置 if (!File.Exists(@PDFPath))//存在PDF,不需要继续转换 { document.ExportAsFixedFormat(PDFPath,Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF); } result = true; } catch (Exception e) { Console.WriteLine(e.Message); result = false; } finally { document.Close(); } return result; } ? ? 摘自https://www.cnblogs.com/alannxu/p/10972947.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |