I created a PDF form with Adobe LiveCycle Designer. I'm now struggling to extract the data programmatically from the PDF after it's been filled out.
I tried to do this using poppler (the qt4 binding, but I guess that doesn't matter), but apparently poppler can't handle XFA forms. Although evince and okular are able to display the form...
As far as I understand, the PDF contains an XDP which in turn contains the XFA form. My question is, how can I extract that data from the PDF?
If there are libraries, c++, java, python or PHP are my options.
To convert XFA PDF to normal PDF, click the Print button, on the Print window that opens, tick Print as Image, and click Print. The XFA form will be converted to a PDF file that you can open with any PDF reader.
To identify an XFA document, you can check the XFAForm feature in the PDF OutputProfile: boolean xfa = pdf.
XFA (also known as XFA forms) stands for XML Forms Architecture, a family of proprietary XML specifications that was suggested and developed by JetForm to enhance the processing of web forms. It can be also used in PDF files starting with the PDF 1.5 specification.
The XML document (in XDP format) that makes up the XFA is stored as the value of the XFA key in the AcroForm dictionary (Interactive Form Dictionary). The AcroForm dictionary is referenced from the Catalog dictionary (Root of the PDF document).
The XFA value can be a stream or an array of streams. If it's a stream, it contains the entire XML document. If it's an array, the different streams contain the separate XDP packets. Concatenating them will give the full XML document.
One of the XDP packets is the dataSets packet. The actual form data will be in a child element of this packet: xfa:data. Example:
<xfa:dataSets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<xfa:data>
<!-- arbitrary XML data, e.g.: -->
<Employee>
<FirstName>John</FirstName>
<Name>Doe</Name>
</Employee>
</xfa:data>
</xfa:dataSets>
Any PDF library that offers low-level access to PDF objects can be used to extract the XML document. Simply navigate through Catalog > AcroForm > XFA.
Some PDF libraries may offer a more high-level convenience method.
(Disclaimer: I'm an iText Software employee.)
For example, using iText (Java) you can simply do this to get the XFA as an org.w3c.dom.Document
:
PdfReader reader = new PdfReader(pdfFile);
XfaForm xfa = reader.getAcroFields().getXfa();
org.w3c.dom.Document doc = xfa.getDomDocument();
Or to just get the dataSets packet as an org.w3c.dom.Node
:
org.w3c.dom.Node datasets = xfa.getDatasetsNode();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With