asp.net中,把word文档转为PDF格式文件的问题。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了asp.net中,把word文档转为PDF格式文件的问题。相关的知识,希望对你有一定的参考价值。
我现在需要做一个把word文档转为PDF格式文件的网页,纯代码的方式我没找着,用第三方组件Aspose.Words.dll转换又出现乱码的问题,求一个纯代码,或者是用第三方组件把word文档转换为PDF文件不出现乱码的方法。
对了,那种需要安装这样那样软件才能实现转换的就算了,要了没用
1、添加引用: Microsoft.Office.Interop.Word版本12.0.0.0; 2、在开头添加命名空间引用:using Microsoft.Office.Interop.Word; 3、具体实现方法如下:
//Word转换成pdf
///<summary>
/// 把Word文件转换成为PDF格式文件 ///</summary>
///<param name="sourcePath">源文件路径</param> ///<param name="targetPath">目标文件路径</param> ///<returns>true=转换成功</returns>
privatebool WordToPDF(string sourcePath, string targetPath)
bool result = false;
Microsoft.Office.Interop.Word.WdExportFormat exportFormat = Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF; object paramMissing = Type.Missing;
Microsoft.Office.Interop.Word.ApplicationClass wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document wordDocument = null; try
object paramSourceDocPath = sourcePath; string paramExportFilePath = targetPath;
Microsoft.Office.Interop.Word.WdExportFormat paramExportFormat = exportFormat;
bool paramOpenAfterExport = false;
Microsoft.Office.Interop.Word.WdExportOptimizeFor paramExportOptimizeFor = Microsoft.Office.Interop.Word.WdExportOptimizeFor.wdExportOptimizeForPrint; Microsoft.Office.Interop.Word.WdExportRange paramExportRange = Microsoft.Office.Interop.Word.WdExportRange.wdExportAllDocument; int paramStartPage = 0; int paramEndPage = 0;
Microsoft.Office.Interop.Word.WdExportItem paramExportItem = Microsoft.Office.Interop.Word.WdExportItem.wdExportDocumentContent; bool paramIncludeDocProps = true; bool paramKeepIRM = true;
Microsoft.Office.Interop.Word.WdExportCreateBookmarks paramCreateBookmarks = Microsoft.Office.Interop.Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks; bool paramDocStructureTags = true; bool paramBitmapMissingFonts = true; bool paramUseISO19005_1 = false;
wordDocument = wordApplication.Documents.Open(
ref paramSourceDocPath, 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(paramExportFilePath, paramExportFormat, paramOpenAfterExport,
paramExportOptimizeFor, paramExportRange, paramStartPage, paramEndPage, paramExportItem, paramIncludeDocProps, paramKeepIRM, paramCreateBookmarks, paramDocStructureTags, paramBitmapMissingFonts, paramUseISO19005_1, ref paramMissing);
result = true;
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; GC.Collect();
GC.WaitForPendingFinalizers(); GC.Collect();
GC.WaitForPendingFinalizers(); catch
result = false;
if (wordDocument != null)
wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing); wordDocument = null;
if (wordApplication != null) 参考技术A 上网搜一个小插件,安装之后,在WORD里面点开始,另存为的时候就会有存为PDF文件选项。这样保存的PDF不会有乱码,而且在不同电脑上(字体可能会有所不同)也不会出现错位现象。追问
你这话说了和没说差不多
如何把Latex自动转为Word
1、首先需要确保安装了Tex2Word20这款软件,先在桌面右键,弹出的太菜单中点击新建,创建一个word文档。
2、然后打开word文档,点击文件,在点击打开”,会谈弹出打开对话框。
3、接着点击“文件类型”,在里面选“Tex(*.tex)”的格式,然后找到需要转化的Tex文件,点“打开”就能转化了。
4、最后打开后,软件会自动将tex文件的内容转化成word文档。
以上是关于asp.net中,把word文档转为PDF格式文件的问题。的主要内容,如果未能解决你的问题,请参考以下文章