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

ITEXT and PDFBOX is not detecting all the form fields present in the pdf

在这段代码中,我使用 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());

PDF FILE HERE IN THIS LINK

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

PDF 中的全局 AcroForm 表单定义仅包含 2 个字段,Text Field 6Text Field 7,它们恰好是第二页上的两个字段.

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

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