用Word写博客园文章

简介:   http://www.cnblogs.com/dunitian/services/metablogapi.aspx   效果如下: 啦啦啦啦啦啦我是卖报的小行家 /// /// Word转换成PDF /// /// 载入...

 

http://www.cnblogs.com/dunitian/services/metablogapi.aspx

 

效果如下:

啦啦啦啦啦啦我是卖报的小行家

/// <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

}

作者: 毒逆天
打赏: 18i4JpL6g54yAPAefdtgqwRrZ43YJwAV5z
本文版权归作者和博客园共有。欢迎转载,但必须保留此段声明,且在文章页面明显位置给出原文连接!
目录
相关文章
|
存储 关系型数据库 Java
数据COOL谈第3期
本文整理自阿里巴巴大淘宝技术部双12队长朱成(锡泽),阿里巴巴业务平台双11队长徐培德(裴度),阿里巴巴数据库双11队长陈锦赋(智盛),InfoQ主编王一鹏,在数据COOL谈第3期的分享。
|
C# C++
Cool说丨819
819. 最常见的单词
94 0
|
C# C++
Cool说丨717与674
717. 1比特与2比特字符 674. 最长连续递增序列
72 0
|
自然语言处理 C# C++
Cool说丨970与720
970. 强整数 720. 词典中最长的单词
102 0
|
人工智能 BI C#
Cool说丨884与1207
[884. 两句话中的不常见单词](https://leetcode-cn.com/problems/uncommon-words-from-two-sentences/) [1207. 独一无二的出现次数](https://leetcode-cn.com/problems/unique-number-of-occurrences/)
93 0
|
存储 Cloud Native Oracle
数据COOL谈第1期
本文整理自PingCap联合创始人兼CTO黄东旭,阿里云数据库产品事业部负责人李飞飞,华东师范大学副校长周傲英,InfoQ主编王一鹏,在数据COOL谈第1期的分享。
|
存储 Cloud Native 关系型数据库
数据COOL谈第4期
本文整理自极客邦科技事业合伙人InfoQ极客传媒总经理汪丹,中国信通院数据库应用创新实验室负责人姜春宇,Forrester首席分析师穆飞,金融行业数据库资深专家韩锋,在数据COOL谈第4期的分享。