时间:2016-02-15 21:35 来源: 我爱IT技术网 作者:佚名
欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【ASP.NET实现将word文档转换成pdf的方法】,下面是详细的讲解!
ASP.NET实现将word文档转换成pdf的方法
/// <summary>/// 把Word文件转换成pdf文件
/// </summary>
/// <param name="sourcePath">需要转换的文件路径和文件名称</param>
/// <param name="targetPath">转换完成后的文件的路径和文件名名称</param>
/// <returns>成功返回true,失败返回false</returns>
public static bool WordToPdf(string sourcePath, string targetPath)
{
bool result=false;
WdExportFormat wdExportFormatPDF=WdExportFormat.wdExportFormatPDF;//转换格式1.wdExportFormatPDF转换成pdf格式 2.wdExportFormatXPS转换成xps格式
object missing=Type.Missing;
Microsoft.Office.Interop.Word.ApplicationClass applicationClass=null;
Document document=null;
try
{
applicationClass=new Microsoft.Office.Interop.Word.ApplicationClass();
object inputfileName=sourcePath;//需要转格式的文件路径
string outputFileName=targetPath;//转换完成后PDF或XPS文件的路径和文件名名称
WdExportFormat exportFormat=wdExportFormatPDF;//导出文件所使用的格式
bool openAfterExport=false;//转换完成后是否打开
WdExportOptimizeFor wdExportOptimizeForPrint=WdExportOptimizeFor.wdExportOptimizeForPrint;//导出方式1.wdExportOptimizeForPrint针对打印进行导出,质量较高,生成的文件大小较大。2.wdExportOptimizeForOnScreen 针对屏幕显示进行导出,质量较差,生成的文件大小较小。
WdExportRange wdExportAllDocument=WdExportRange.wdExportAllDocument;//导出全部内容(枚举)
int from=0;//起始页码
int to=0;//结束页码
WdExportItem wdExportDocumentContent=WdExportItem.wdExportDocumentContent;//指定导出过程中是否只包含文本或包含文本的标记.1.wdExportDocumentContent:导出文件没有标记,2.导出文件有标记
bool includeDocProps=true;//指定是否包含新导出的文件在文档属性
bool keepIRM=true;//
WdExportCreateBookmarks wdExportCreateWordBookmarks=WdExportCreateBookmarks.wdExportCreateWordBookmarks;//1.wdExportCreateNoBookmarks:不要在导出文件中创建书签,2.wdExportCreateHeadingBookmarks:标题和文本框导出的文件中创建一个书签,3.wdExportCreateWordBookmarks每个字的书签,其中包括除包含页眉和页脚中的所有书签导出的文件中创建一个书签。
bool docStructureTags=true;
bool bitmapMissingFonts=true;
bool UseISO19005_1=false;//生成的文档是否符合 ISO 19005-1 (PDF/A)
document=applicationClass.Documents.Open(ref inputfileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
if (document !=null)
{
document.ExportAsFixedFormat(outputFileName, exportFormat, openAfterExport, wdExportOptimizeForPrint, wdExportAllDocument, from, to, wdExportDocumentContent, includeDocProps, keepIRM, wdExportCreateWordBookmarks, docStructureTags, bitmapMissingFonts, UseISO19005_1, ref missing);
}
result=true;
}
catch
{
result=false;
}
finally
{
if (document !=null)
{
document.Close(ref missing, ref missing, ref missing);
document=null;
}
if (applicationClass !=null)
{
applicationClass.Quit(ref missing, ref missing, ref missing);
applicationClass=null;
}
}
return result;
}
关于ASP.NET实现将word文档转换成pdf的方法的用户互动如下:
相关问题:
答: >>详细
相关问题:
答: >>详细
相关问题:
答: >>详细
- 【创建】ASP.NET Web API教程 创建域模型的方法详
- 【服务器】asp.net页面状态管理cookie和服务器状
- 【Repeater控件】.NET实现Repeater控件+AspNetPag
- 【客户端】获取客户端IP地址c#/vb.net各自实现代
- 【asp】asp.net上传execl文件后 在页面上加载显示
- 【Excel】页面导出为Excel的时间格式的问题-时间
- 【ref】asp.net(c#)ref out params的区别-out-pa
- 【数据控件】asp.net获得数据控件事件索引并获取
- 【NET】10个.NET中删除空白字符串的方法-删除空白
- 【web】web.config配置连接字符串的方法-config配
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
