2011-07-04 34 views
0

我想務實地將office文檔轉換爲pdf.i,不想使用Microsoft Office服務ddl。 這是我想用一個組件不是com.does人知道任何可能幫助我嗎?我想itextsharp.it不做轉換,我使用的代碼,將office文檔轉換爲pdf中的c#

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(); 

。而cutepdf無法直接轉換爲pdf。請幫我解決這個問題。我嘗試了ghostscript。但它將postscripts轉換爲pdf我找不到辦公室文件轉換爲.ps。有沒有其他免費的圖書館可以用來滿足我的要求?

請幫我在這裏 感謝名單

回答

0

最近我看了很多的自由軟件將文檔轉換爲PDF,我必須承認,他們沒有被滿足我的要求。一些轉換器並不壞,但許可證限制。我想你必須找到一個好的非自由轉換器。

你可以看看PDF轉換器的這個名單:Converters

+0

有什麼建議嗎?你能告訴我幾個你已經嘗試過的嗎?我不會介意,只要它是一個ddl。 –

0

我建議自動化Open Office來完成轉換。它是免費的,以我的經驗用於自動轉換任務時比Microsoft Office更穩定。

查看我對類似問題的回答here,其中包括一個代碼示例。