首页 > 解决方案 > 如何使用 PDFBox 获取输入字段的标题

问题描述

我想从 pdf 文件中获取所有字段并获取所有必需的数据:字段类型、id、默认值、标题、弹出文本等。除了标题,我几乎可以获得所有数据。如果我做对了,我可以在 pdf 内容章节中找到正确的字段标题,但是如何将它们与字段匹配?我使用此代码来获取字段信息。

try(PDDocument document = Loader.loadPDF(pdfFileBinary)) {
    PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
    if (acroForm == null) {
        return Collections.emptyList();
    }
    return acroForm.getFields()
            .stream()
            .flatMap(unfoldFunction)
            .map(PdfFieldImpl::new)
            .collect(Collectors.toList());
} catch (IOException e) {
   throw new RuntimeException("Can't parse pdf document");
}

如果有人知道解决方案但使用不同的库,那也很棒。对不起,如果这对你来说太愚蠢了:)

标签: javapdfitextpdfbox

解决方案


推荐阅读