0

我有如图所示的 PDF 文件。FORM_PDF

在 Java 中使用 PDFBox 我检索了表单字段的文本。我的代码:

    File file = new File("example.pdf");
    PDDocument doc = PDDocument.load(file);
    PDDocumentCatalog catalog = doc.getDocumentCatalog();
    PDAcroForm form = catalog.getAcroForm();
    PDFieldTree fields = form.getFieldTree();

    for (PDField field : fields) {
        Object value = field.getValueAsString();
        String name = field.getPartialName();
        System.out.print(name);
        System.out.print(" = ");
        System.out.print(value);
        System.out.println();
    }

输出 :

  • 给定名称文本框 = Jignesh
  • 姓氏文本框 = Jignesh
  • 房屋编号文本框 = xyz
  • 地址 2 文本框 = pqr

我也想在下面检索

  1. 给定的名称:
  2. 姓:
  3. 地址1:

作为

  • 给定名称文本 = 给定名称:
  • 姓氏文本 = 姓氏:
  • 房屋编号文本 = 地址 1:
  • 地址 2 文本 = 地址 2:

由于上面是表单字段,因此所有字段都可以轻松检索。我什至想提取表单的标签,因为我想映射它们。

请帮忙。非常感谢。

4

0 回答 0