2013-12-07 45 views
0

在使用Adobe Acrobat XI,編輯PDF表單時,有自動化的Adobe PDF表單導入/導出數據功能

下功能

工具 - >窗體 - >更多表單選項 - >導入數據
工具 - >表格 - >更多表單選項 - >導出數據

導入數據採用XML文件並將數據導入到PDF中。導出顯然是根據輸入到當前表單的數據創建一個XML文件。

我需要在.Net應用程序中模擬此功能。 (理想的基於網絡)。

是否有任何第三方庫(iTextSharp?)可以接受PDF文件和XML文件並輸出從XML導入數據的PDF?或者使用Acrobat本地庫最適合自動執行此操作?

有沒有人有使用第三方庫或Adobe組件做類似於此事的例子?

注:我需要導入/導出的PDF表單不是在內部創建的。具體而言,我需要使用由專利局創建的PDF表單進行此操作。 (SB08a信息公開聲明)

http://www.uspto.gov/patents/process/file/efs/guidance/updated_IDS.pdf

謝謝!

+1

檢查了這一點http://stackoverflow.com/a/5638922/231316以及http://stackoverflow.com/questions/tagged/xfa+itextsharp –

回答

1

我發現我可以從ITextSharp庫中獲得所需的行爲。

/// <summary> 
    /// Exports XFA data from a PDF File. 
    /// </summary> 
    /// <param name="populatedPDFForm">a readable stream of the PDF with a populated form</param> 
    /// <returns>A stream containing the exported XML form data</returns> 
    public static System.IO.MemoryStream Export(System.IO.Stream populatedPDFForm) 
    { 
     System.IO.MemoryStream outputStream = new System.IO.MemoryStream(); 
     using (iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(populatedPDFForm)) 
     { 
      var settings = new System.Xml.XmlWriterSettings { Indent = true }; 
      using (var writer = System.Xml.XmlWriter.Create(outputStream, settings)) 
      { 
       reader.AcroFields.Xfa.DatasetsNode.WriteTo(writer); 
      } 
     } 
     return outputStream; 
    } 

    /// <summary> 
    /// Imports XFA Data into a new PDF file. 
    /// </summary> 
    /// <param name="pdfTemplate">A PDF File with an unpopulated form.</param> 
    /// <param name="xmlFormData">XFA form data in XML format.</param> 
    /// <returns>a memorystream containing the new PDF file.</returns> 
    public static System.IO.MemoryStream Import(System.IO.Stream pdfTemplate, System.IO.Stream xmlFormData) 
    { 
     System.IO.MemoryStream outputSteam = new System.IO.MemoryStream(); 
     using (iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(pdfTemplate)) 
     { 
      using (iTextSharp.text.pdf.PdfStamper stamper = new iTextSharp.text.pdf.PdfStamper(reader, outputSteam)) 
      { 
       stamper.Writer.CloseStream = false; 
       stamper.AcroFields.Xfa.FillXfaForm(xmlFormData); 
      } 
     } 
     return outputSteam; 
    } 
+0

我想這兩種功能,導出()的工作原理很好,但在Import()中有一個問題。我有相當複雜的PDF格式,導入數據後,我試圖打開它,Adobe Reader anounced文件已損壞。解決方案是通過在這一行上擴展參數來允許壓模追加到現有的pdf上:'使用(iTextSharp.text.pdf.PdfStamper stamper = new iTextSharp.text.pdf.PdfStamper(reader,outputSteam,'\ 0',true ))' –