Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Java and IText, how to extract AcroForm field names from a PDF?

Tags:

java

pdf

itext

I'm looking for a simple API example, that reads a PDF file / template as an input, and iterates over the fields defined in the PDF form (I think it is called AcroForm)

like image 515
Eran Medan Avatar asked Feb 26 '23 19:02

Eran Medan


1 Answers

Ok, I have found the solution

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();
    }
}
like image 139
Eran Medan Avatar answered Mar 01 '23 09:03

Eran Medan