用Word写博客园文章
?
http://www.cnblogs.com/dunitian/services/metablogapi.aspx
?
效果如下:
啦啦啦啦啦啦我是賣報(bào)的小行家
| /// <summary> /// Word轉(zhuǎn)換成PDF /// </summary> /// <param name="inputPath">載入路徑</param> /// <param name="outputPath">保存路徑</param> /// <param name="startPage">初始頁(yè)碼(默認(rèn)為第一頁(yè)[0])</param> /// <param name="endPage">結(jié)束頁(yè)碼(默認(rèn)為最后一頁(yè))</param> public static bool WordToPDF(string inputPath, string outputPath, int startPage = 0, int endPage = 0) { bool b = true; ? #region初始化 //初始化一個(gè)application Application wordApplication = new Application(); //初始化一個(gè)document Document wordDocument = null; #endregion ? #region參數(shù)設(shè)置~~我去累死寶寶了~~ //word路徑 object wordPath = Path.GetFullPath(inputPath); ? //輸出路徑 string pdfPath = Path.GetFullPath(outputPath); ? //導(dǎo)出格式為PDF WdExportFormat wdExportFormat = WdExportFormat.wdExportFormatPDF; ? //導(dǎo)出大文件 WdExportOptimizeFor wdExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint; ? //導(dǎo)出整個(gè)文檔 WdExportRange wdExportRange = WdExportRange.wdExportAllDocument; ? //開始頁(yè)碼 int startIndex = startPage; ? //結(jié)束頁(yè)碼 int endIndex = endPage; ? //導(dǎo)出不帶標(biāo)記的文檔(這個(gè)可以改) WdExportItem wdExportItem = WdExportItem.wdExportDocumentContent; ? //包含word屬性 bool includeDocProps = true; ? //導(dǎo)出書簽 WdExportCreateBookmarks paramCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks; ? //默認(rèn)值 object paramMissing = Type.Missing; ? #endregion ? #region轉(zhuǎn)換 try { //打開word wordDocument = wordApplication.Documents.Open(ref wordPath, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing); //轉(zhuǎn)換成指定格式 if (wordDocument != null) { wordDocument.ExportAsFixedFormat(pdfPath, wdExportFormat, false, wdExportOptimizeFor, wdExportRange, startIndex, endIndex, wdExportItem, includeDocProps, true, paramCreateBookmarks, true, true, false, ref paramMissing); } } catch (Exception ex) { b = false; } finally { //關(guān)閉 if (wordDocument != null) { wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing); wordDocument = null; } ? //退出 if (wordApplication != null) { wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing); wordApplication = null; } } ? return b; #endregion } |
轉(zhuǎn)載于:https://www.cnblogs.com/dunitian/p/5041062.html
總結(jié)
以上是生活随笔為你收集整理的用Word写博客园文章的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 3.7 代码注释和编码规范
- 下一篇: 打通两台机器的ssh功能