C# word转pdf
写在最前面,如果要部署,服务器需要安装相同版本的office,否则会出现一大堆问题 https://www.cnblogs.com/5426z/articles/4865312.html
需要单独引入的是COM中的Microsoft Office 12.0 Object Library
public static bool WordToPDF(string sourcePath, string targetPath)
{
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);
document.ExportAsFixedFormat(targetPath, WdExportFormat.wdExportFormatPDF);
result = true;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
result = false;
}
finally
{
document.Close();
application.Quit();
}
return result;
}
参考: https://www.cnblogs.com/wangxlei/p/9431149.html