使用Java和IText,如何从PDF中提取AcroForm字段名称?

问题描述 投票:4回答:1

我正在寻找一个简单的API示例,它将PDF文件/模板作为输入读取,并迭代PDF表单中定义的字段(我认为它被称为AcroForm)

java pdf itext
1个回答
8
投票

好的,我找到了解决方案

public static void scanFields(String path) throws IOException {
    PdfReader pdfReader = new PdfReader(path);
    AcroFields acroFields = pdfReader.getAcroFields();
    HashMap<String,AcroFields.Item> fields = acroFields.getFields();
    Set<Entry<String, Item>> entrySet = fields.entrySet();
    for (Entry<String, Item> entry : entrySet) {
        String key = entry.getKey();
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.