使用?Microsoft.Office.Interop.Word 將word文檔轉(zhuǎn)為PDF
在NuGet中搜索?Microsoft.Office.Interop.Word 安裝
方法 參數(shù)參考?微軟官網(wǎng)地址文章來源:http://www.zghlxwxcb.cn/news/detail-537701.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-537701.html
/// <summary>
/// 將word轉(zhuǎn)成PDF office
/// </summary>
/// <param name="sourcePath"></param>
/// <param name="targetPath"></param>
/// <returns></returns>
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);
/*
參數(shù)參考 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;
}
到了這里,關(guān)于C#將word文檔轉(zhuǎn)為PDF的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!