引用wps进行word转pdf操作
引用wps进行word转pdf操作
https://blog.csdn.net/dqizi123/article/details/116935764
1.在安装的wps下复制 etapi.dll,wppapi.dll,wpsapi.dll,这三个文件可以操作word,powerpoint,excel;
2.点击word引用,属性-》嵌入互操作类型-》false;
3.代码:word转pdf;
using wps= Word;
public static bool ConvertToPdf(string sourcePath, string targetPath)
{
Word.ApplicationClass app = new Word.ApplicationClass();
//WPS.ApplicationClass app = new WPS.ApplicationClass();
Word.Document doc = null;
try
{
// doc = app.Documents.Open(sourcePath, true, true, false, null, null, false, "", null, 100, 0, true, true, 0, true);
doc = app.Documents.Open(sourcePath, Visible: false);
doc.ExportAsFixedFormat(targetPath, wps.WdExportFormat.wdExportFormatPDF);
//doc.ExportPdf(targetPath, "", "");
}
catch (Exception ex)
{
LogHelper.WriteLog("err", ex);
return false;
}
finally
{
doc.Close();
app.Quit();
}
return true;
}
————————————————
版权声明:本文为CSDN博主「dqizi123」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/dqizi123/article/details/116935764