How can I merge data into an XDP file and return a PDF (via .NET)?

风格不统一 提交于 2019-12-01 06:15:43

Hey, sorry for the slow reply, didn't see this.

Create the PDF. Encode it as base64.

Create a text file, foo.xdp:

<?xml version='1.0' encoding='UTF-8'?>
<?xfa generator='AdobeDesigner_V7.0' APIVersion='2.2.4333.0'?>
<xdp:xdp xmlns:xdp='http://ns.adobe.com/xdp/'>
    <xfa:datasets xmlns:xfa='http://www.xfa.org/schema/xfa-data/1.0/'>
        <xfa:data>

Insert the XML here that is your dynamic data, matching the dynamic fields in the PDF.

        </xfa:data>
    </xfa:datasets>
    <pdf xmlns=\"http://ns.adobe.com/xdp/pdf/\"><document>
       <chunk>

Without putting any characters after the tag, insert the base64 encoded PDF.

        </chunk>
    </document></pdf>
</xdp:xdp>

And, lo and behold, you have a valid XDP. Adobe Reader will accept this and display the PDF with your values in it.

In Java, if you have a Properties with the connection details in it, the following code can use Livecycle to turn an XDP to a PDF, although your mileage might vary in C#.

        // Create a ServiceClientFactory object
        ServiceClientFactory myFactory = ServiceClientFactory
                .createInstance(connectionProperties);

        // Create a PDF Utility client
        PDFUtilityServiceClient pdfClient = new PDFUtilityServiceClient(myFactory);

        // Specify an XDP file to convert to a PDF document
        ByteArrayInputStream bais = new ByteArrayInputStream(xdp.getBytes("ASCII"));
        Document inDoc = new Document(bais);

        // Convert the XDP file to a PDF document
        Document pdf = pdfClient.convertXDPtoPDF(inDoc);

        // Return the PDF as an InputStream.
        return pdf.getInputStream();

Sounds like you're looking for client-side rendering - something that I've never really been able to use in a workable fashion. And given that you're working in .Net it'll probably make things impossible..

In my opinion your best bet will definitely be to use the render service that comes with Forms ES. Probably doesn't help much, but hey :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!