Recently had a requirement to have a web application serve up a Fillable PDF Form that was to be filled in using data from a database. I found that this could be done by sending data in Adobe’s XDP format to the client browser. XDP is an XML version of a PDF document. It also allows a linked PDF to be supplied with embedded data. I could never locate an official schema definition, but a simple one looks something like:
<?xml version="1.0" encoding="UTF-8" ?>
<?xfa generator="XFA2_4" APIVersion="2.4.5234.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>
<!-- Place data here to bind to PDF -->
</xfa:data>
</xfa:datasets>
<pdf href="http://localhost/PdfForms/MyForm.pdf"
xmlns="http://ns.adobe.com/xdp/pdf/" />
</xdp:xdp>
You can see the link to the actual PDF in the href attribute of the <pdf> tag. This is the location of the “to be filled” PDF.
By sending this to the browser with a content type of "application/vnd.adobe.xfdf", Acrobat Reader will then open the PDF specified and attempt to fill it with the data provided in the <xfa:data> tags. You can simply supply the PDF field names and values to fill in data (<firstname>Ray</firstname>), but in my case I had more complex forms with repeatable sections so I wanted something a little more structured. It turns out that Adobe Designer 7 allows you to databind fields against an XSD. You can drag and drop the XSD elements directly on fields in the PDF. Your XDP may then contain data in the format specified by your XSD like so:
<?xml version="1.0" encoding="UTF-8" ?>
<?xfa generator="XFA2_4" APIVersion="2.4.5234.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>
<MyForm xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://hdri.net/MyForm.xsd">
<FirstName>Ray</FirstName>
<LastName>Houston</LastName>
</MyForm>
</xfa:data>
</xfa:datasets>
<pdf href="http://localhost/PdfForms/MyForm.pdf"
xmlns="http://ns.adobe.com/xdp/pdf/" />
</xdp:xdp>
MyForm is a simple object that contains properties for each field of data. By using the XSD.exe utility, I was able to generate the XSD I needed to do my databinding in Adobe Designer.
At runtime, I serialized MyForm to XML and did an XSLT transformation to the XDP format which I served to the client using a custom HttpHandler.