ITEXT和PDFBOX并未检测到PDF中存在的所有表单字段

发布于 2025-01-18 02:18:50 字数 634 浏览 3 评论 0原文

在此代码中,我使用itextpdfbox使用Java来查找PDF中的字段数,我正在附上PDF,它有11个字段,但是第1页中存在的字段未被检测到,并且打印的大小为2个。

        PdfDocument doc = new PdfDocument(new PdfReader(file));
        PdfAcroForm form = PdfAcroForm.getAcroForm(doc, true);
        System.out.println("form fields size from Itext:"+form.getFormFields().size());


        PDDocument document = PDDocument.load(file);
        PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
        List<PDField> fields = acroForm.getFields();
        System.out.println("form fields size from PDFBOX:"+fields.size());

In this code I've used for finding the number of fields in the pdf using Itext and PDFBOX with Java, I'm attaching the pdf, it has 11 fields but the fields present in the page 1 are not getting detected and the size being printed is 2 for the cases.

        PdfDocument doc = new PdfDocument(new PdfReader(file));
        PdfAcroForm form = PdfAcroForm.getAcroForm(doc, true);
        System.out.println("form fields size from Itext:"+form.getFormFields().size());


        PDDocument document = PDDocument.load(file);
        PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
        List<PDField> fields = acroForm.getFields();
        System.out.println("form fields size from PDFBOX:"+fields.size());

PDF FILE HERE IN THIS LINK

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老娘不死你永远是小三 2025-01-25 02:18:50

您的 PDF 中的表单信息不一致。

PDF 中的全局 AcroForm 表单定义仅包含 2 个字段:文本字段 6文本字段 7,这两个字段恰好是第二页。

第一页的 Annots 数组引用了十个表单字段小部件,每个部件都与一个表单字段对象合并。这些字段未从 PDF 中的 AcroForm 表单定义中引用。因此,它们不是 PDF 形式的一部分,而只是一些随意的注释。

要解决此问题,只需从 AcroForm 表单定义中引用第一页小部件注释的表单字段即可。

The form information in your PDF is inconsistent.

The global AcroForm form definition in your PDF contains only 2 fields, Text Field 6 and Text Field 7, which happen to be the two fields on page two.

Page one in its Annots array references ten form field widgets, each of them merged with a form field object. These fields are not referenced from the AcroForm form definition in your PDF. Thus, they are not part of the form of the PDF but merely some arbitrary annotations hanging around.

To fix the issue, simply reference the form fields of the widget annotations of page one from the AcroForm form definition.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文