asp.net中,把word文档转为PDF格式文件的问题。
我现在需要做一个把word文档转为PDF格式文件的网页,纯代码的方式我没找着,用第三方组件Aspose.Words.dll转换又出现乱码的问题,求一个纯代码,或者是用第三...
我现在需要做一个把word文档转为PDF格式文件的网页,纯代码的方式我没找着,用第三方组件Aspose.Words.dll转换又出现乱码的问题,求一个纯代码,或者是用第三方组件把word文档转换为PDF文件不出现乱码的方法。
对了,那种需要安装这样那样软件才能实现转换的就算了,要了没用 展开
对了,那种需要安装这样那样软件才能实现转换的就算了,要了没用 展开
2个回答
展开全部
C#编程,将Word转PDF,该方法有一定弊端,但是比起网路上的其他方法来说,还算比较好的,弊端是需要客户机上安装有WORD 2007或更高的版本。
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) {
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |