用Word写博客测试文章(教程+效果)
2016-02-23 10:19
337 查看
效果如下:
啦啦啦啦啦啦我是卖报的小行家
/// <summary> /// Word转换成PDF /// </summary> /// <param name="inputPath">载入路径</param> /// <param name="outputPath">保存路径</param> /// <param name="startPage">初始页码(默认为第一页[0])</param> /// <param name="endPage">结束页码(默认为最后一页)</param> public static bool WordToPDF(string inputPath, string outputPath, int startPage = 0, int endPage = 0) { bool b = true; #region初始化 //初始化一个application Application wordApplication = new Application(); //初始化一个document Document wordDocument = null; #endregion #region参数设置~~我去累死宝宝了~~ //word路径 object wordPath = Path.GetFullPath(inputPath); //输出路径 string pdfPath = Path.GetFullPath(outputPath); //导出格式为PDF WdExportFormat wdExportFormat = WdExportFormat.wdExportFormatPDF; //导出大文件 WdExportOptimizeFor wdExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint; //导出整个文档 WdExportRange wdExportRange = WdExportRange.wdExportAllDocument; //开始页码 int startIndex = startPage; //结束页码 int endIndex = endPage; //导出不带标记的文档(这个可以改) WdExportItem wdExportItem = WdExportItem.wdExportDocumentContent; //包含word属性 bool includeDocProps = true; //导出书签 WdExportCreateBookmarks paramCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks; //默认值 object paramMissing = Type.Missing; #endregion #region转换 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); //转换成指定格式 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 { //关闭 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 } |
相关文章推荐
- windows all version - 实现指定路径共享
- python文档生成工具pydoc在网页上查看的方法
- 【菜鸟学Java】13:代理模式——动态代理这样玩!
- 2月份.wang域名总量15强:排名不变 5家总量上涨
- 第一行代码-8.2 接收和发送短信
- 13. Roman to Integer
- tableview的两个取得重用cell方法的区别
- 安卓开发.SO文件
- 1.0.1 JavaScript Array对象
- 常用代码备份--OLE操作Excel之sheet复制
- ERROR 1005: Can't create table (errno: 121)
- RequireJS进阶(一)
- 学习Javascript面向对象编程之封装
- django项目中如何把sitemap.xml等静态文件放到web根目录
- windows server 2008 - 隐藏磁盘分区 (2)
- jmeter ---处理Cookie与Session
- 使用 Flask 框架写用户登录功能的Demo时碰到的各种坑(二)——使用蓝图功能进行模块化
- Android开发中网络请求的压缩 ── GZip的使用
- git pull更新错误解决办法
- AsyncTask和Handler的优缺点比较