自动化Adobe PDF Form导入/导出数据功能 [英] Automate Adobe PDF Form Import/Export data functions

查看:177
本文介绍了自动化Adobe PDF Form导入/导出数据功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Adobe Acrobat XI中,编辑PDF表单时,

Within Adobe Acrobat XI, when editing PDF forms, there are functions under

工具->表单->更多表单选项->导入数据
工具->表单->更多表单选项->导出数据

Tools -> Forms -> More Form Options -> Import Data
Tools -> Forms -> More Form Options -> Export Data

导入数据获取XML文件,并将数据导入PDF.导出显然会根据输入到当前表单中的数据创建一个XML文件.

Import Data takes an XML file and imports the data into the PDF. Export obviously creates an XML file from the data entered into the current form.

我需要在.Net应用程序中模仿此功能. (最好是基于网络).

I need to mimic this functionality in a .Net application. (ideally web based).

是否有任何第三方库(iTextSharp?)可以获取PDF文件和XML文件,并输出从XML导入数据的PDF?还是使用Acrobat本机库最适合自动执行此操作?

Are there any 3rd party libraries (iTextSharp?) that can take a PDF file and an XML file and output a PDF that has imported the data from the XML? Or would using Acrobat native libraries be best for automating this?

有人有使用第三方库或Adobe组件执行类似操作的示例吗?

Does anyone have an example of doing something similar to this using either a 3rd party library or Adobe components?

注意:我需要从中导入/导出的PDF表单不是在内部创建的.具体来说,我需要使用专利局创建的PDF表单来执行此操作. (SB08a信息披露声明)

Note: The PDF form that I would need to import/export from is NOT created internally. Specifically I need to do this with a PDF form created by the patent office. (SB08a Information Disclosure Statement)

http://www.uspto.gov/patents/进程/文件/efs/guidance/updated_IDS.pdf

谢谢!

推荐答案

我发现我可以从ITextSharp库中获得所需的行为.

I discovered I could get the behavior I needed from the ITextSharp library.

    /// <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;
    }

这篇关于自动化Adobe PDF Form导入/导出数据功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆