Extract xdp or xfa from PDF

ぃ、小莉子 提交于 2019-12-03 13:42:19

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