asp.net中,把word文档转为PDF格式文件的问题
C#编程,将Word转PDF,该方法有一定弊端,但是比起网路上的其他方法来说,还算比较好的,弊端是需要客户机上安装有WORD 2007或更高的版本。
1、添加引用: Microsoft.Office.Interop.Word版本12.0.0.0; 2、在开头添加命名空间引用:using Microsoft.Office.Interop.Word; 3、具体实现方法如下: //Word转换成pdf ///
ASP如何实现将WORD等文档生成成PDF文档
ASP实现将WORD等文档生成成PDF文档方法如下: 一、添加引用 using Microsoft.Office.Interop.Word; 二、转换方法 1、方法 C# 代码 /// /// 把Word文件转换成pdf文件 /// /// 需要转换的文件路径和文件名称 /// 转换完成后的文件的路径和文件名名称 /// 成功返回true,失败返回false 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; }。
如何将WORD格式的文档转化成PDF文件
我在中国计算机报上看到了这篇文章觉得很好,把他推荐给你。
WORD轻松转换PDF文档 可以利用Office 2003中的Microsoft Office Document Imaging组件来实现WORD转换PDF,也就是说利用WORD来完成该任务。 用Adobe Reader打开想转换的PDF文件,接下来选择“文件→打印”菜单,在打开的“打印”窗口中将“打印机”栏中的名称设置为“Microsoft Office Document Image Writer”,确认后将该PDF文件输出为MDI格式的虚拟打印文件。
注:如果没有找到“Microsoft Office Document Image Writer”项,使用Office 2003安装光盘中的“添加/删除组件”更新安装该组件,选中“Office 工具 Microsoft DRAW转换器”。 然后,运行“Microsoft Office Document Imaging”,并利用它来打开刚才保存的MDI文件,选择“工具→将文本发送到Word”菜单,在弹出的窗口中选中“在输出时保持图片版式不变”,确认后系统会提示“必须在执行此操作前重新运行OCR。
这可能需要一些时间”,不管它,确认即可。 注:对PDF转DOC的识别率不是特别完美,转换后会丢失原来的排版格式,所以转换后还需要手工对其进行排版和校对工作。
以上仅在word2003中可用,其他版本没有Microsoft Office Document Image Writer。 (文 胡斌) 。
转载请注明出处51数据库 » asp.netword转pdf组件
裤裆里藏炸弹