Extract xdp or xfa from PDF

你离开我真会死。 提交于 2019-12-04 20:47:24

问题


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.


回答1:


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();


来源:https://stackoverflow.com/questions/18587878/extract-xdp-or-xfa-from-pdf

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