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;
}