在c#中将office文档转换为pdf

我想务实地将office文档转换为pdf.i不想使用microsoft office service ddl。 这是我用的代码,

using System; using System.IO; using Microsoft.Office.Interop.Word; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.IO.Compression; using Document = Microsoft.Office.Interop.Word.Document; namespace pdfconversion { public class PdfMerge { static void Main() { var wordApplication = new Microsoft.Office.Interop.Word.Application(); Document wordDocument = null; object paramSourceDocPath = @"C:\testfile.doc"; object paramMissing = Type.Missing; string paramExportFilePath = @"C:\Temp\Test1234.xps"; WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatXPS; bool paramOpenAfterExport = false; WdExportOptimizeFor paramExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint; WdExportRange paramExportRange = WdExportRange.wdExportAllDocument; int paramStartPage = 0; int paramEndPage = 0; WdExportItem paramExportItem = WdExportItem.wdExportDocumentContent; bool paramIncludeDocProps = true; bool paramKeepIRM = true; WdExportCreateBookmarks paramCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks; bool paramDocStructureTags = true; bool paramBitmapMissingFonts = true; bool paramUseISO19005_1 = false; try { // Open the source document. 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); // Export it in the specified format. if (wordDocument != null) wordDocument.ExportAsFixedFormat(paramExportFilePath, paramExportFormat, paramOpenAfterExport, paramExportOptimizeFor, paramExportRange, paramStartPage, paramEndPage, paramExportItem, paramIncludeDocProps, paramKeepIRM, paramCreateBookmarks, paramDocStructureTags, paramBitmapMissingFonts, paramUseISO19005_1, ref paramMissing); } catch (Exception ex) { // Respond to the error } finally { // Close and release the Document object. if (wordDocument != null) { wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing); wordDocument = null; } // Quit Word and release the ApplicationClass object. if (wordApplication != null) { wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing); wordApplication = null; } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); 

我想使用汇编而不是com.does任何人都知道任何可能对我有帮助的东西?我试过itextsharp.it不做转换。 和cutepdf无法直接转换为pdf。 请帮帮我。我试过ghostscript。 但它将postcripts转换为pdf我无法找到将office文档转换为.ps的方法。 有没有其他免费图书馆,我可以用来满足我的要求?

请帮帮我在这里

我最近看了很多免费软件将文档转换成PDF,我必须承认它们都不符合我的要求。 一些转换器并不坏,但许可证是限制性的。 我想你必须找到一个好的非自由转换器。

您可以查看PDF转换器列表: 转换器

实际上,我所知道的方法与你相似。 但是我从博客文章中找到了一个使用第三方组件的简单方法。

http://stephenchy520.blog.com/2011/11/24/how-to-convert-word-doc-to-pdf-for-cvb-net/

也许这篇文章中的方法对你有帮助。

我建议自动化Open Office进行转换。 它是免费的,根据我的经验,当用于自动转换任务时,它比Microsoft Office更稳定。

请在此处查看我对类似问题的回答,其中包括代码示例。