Convert Office documents to pdf format (2)

Convert Office documents to pdf format (2) In the previous article, we used Microsoft Office components to convert Word, Excel, and Powerpoint into pdf format. In this article, we will use the WPS Office component for conversion. The steps are as follows: ① Add relevant references to WPS components Note: wpsapi.dll corresponds to the Word file API; etapi.dll corresponds to the Excel file API; wppapi corresponds to the PPT file API; ②Writing Office Help Class public class WPSOfficeHelper { /// /// Convert Word to pdf file , suitable for (.doc, .docx, .mht, .htm file types) /// /// Source file /// Target file /// public static bool WordToPdf(string sourceFileName, string targetFileName) { Word.Application wordApp = newWord.Application(); Word._Document wordDoc = null; try { wordApp.Visible = false; wordDoc = wordApp.Documents.Open(sourceFileName, false, true); wordDoc.ExportAsFixedFormat(targetFileName, Word.WdExportFormat.wdExportFormatPDF); return true span>; } catch (Exception ex ) { return false span>; } finally { if (wordDoc != null) { wordDoc.Close(false); wordDoc = null; } if (wordApp != null) { wordApp.Quit(false); wordApp = null; } } } /// /// Excel converted to pdf file /// /// Source file /// Target file /// public static bool ExcelToPdf(string sourceFileName, string targetFileName) { Excel.Application excelApp = new Excel.Application(); Excel._Workbook excelDoc = null;…

Convert Office documents to pdf format (2)

Convert Office documents to pdf format (2) In the previous article, we used Microsoft Office components to convert Word, Excel, and Powerpoint into pdf format. In this article, we will use the WPS Office component for conversion. The steps are as follows: ① Add relevant references to WPS components Note: wpsapi.dll corresponds to the Word file API; etapi.dll corresponds to the Excel file API; wppapi corresponds to the PPT file API; ②Writing Office Help Class public class WPSOfficeHelper { /// /// Convert Word to pdf file , suitable for (.doc, .docx, .mht, .htm file types) /// /// Source file /// Target file /// public static bool WordToPdf(string sourceFileName, string targetFileName) { Word.Application wordApp = newWord.Application(); Word._Document wordDoc = null; try { wordApp.Visible = false; wordDoc = wordApp.Documents.Open(sourceFileName, false, true); wordDoc.ExportAsFixedFormat(targetFileName, Word.WdExportFormat.wdExportFormatPDF); return true span>; } catch (Exception ex ) { return false span>; } finally { if (wordDoc != null) { wordDoc.Close(false); wordDoc = null; } if (wordApp != null) { wordApp.Quit(false); wordApp = null; } } } /// /// Excel converted to pdf file /// /// Source file /// Target file /// public static bool ExcelToPdf(string sourceFileName, string targetFileName) { Excel.Application excelApp = new Excel.Application(); Excel._Workbook excelDoc = null;…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索