从PDF提取xdp或xfa [英] Extract xdp or xfa from PDF

查看:258
本文介绍了从PDF提取xdp或xfa的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Adobe LiveCycle Designer创建了一个PDF表单.现在,我正在努力以编程方式从PDF中提取数据.

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.

我尝试使用poppler(qt4绑定,但我想没关系)来做到这一点,但显然poppler无法处理XFA表单.尽管evince和okular可以显示表格...

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...

据我了解,PDF包含一个XDP,而XDP则包含XFA表格.我的问题是,如何从PDF中提取数据?

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?

如果有库,我可以选择c ++,java,python或PHP.

If there are libraries, c++, java, python or PHP are my options.

推荐答案

组成XFA的XML文档( XDP格式)存储为<​​strong> XFA 的值 AcroForm 词典(交互式表格词典)中的"strong"键. AcroForm 词典是从 Catalog 词典(PDF文档的 Root )引用的.

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).

XFA 值可以是一个流或一组流.如果是流,则包含整个XML文档.如果是数组,则不同的流包含单独的XDP数据包.串联它们将提供完整的XML文档.

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.

XDP数据包之一是 dataSets 数据包.实际的表单数据将在此数据包的子元素中: xfa:data .示例:

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>

任何提供对PDF对象的低级访问的PDF库都可以用来提取XML文档.只需浏览目录> AcroForm > XFA .

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.

某些PDF库可能会提供更高级的便捷方法.

Some PDF libraries may offer a more high-level convenience method.

(免责声明:我是iText Software的员工.) 例如,使用iText(Java),您只需执行以下操作即可将XFA用作org.w3c.dom.Document:

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

或者只是将 dataSets 数据包作为org.w3c.dom.Node:

Or to just get the dataSets packet as an org.w3c.dom.Node:

org.w3c.dom.Node datasets = xfa.getDatasetsNode();

这篇关于从PDF提取xdp或xfa的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆