Extract AcroForm - Extract Form Data from PDF in Java
Contents
[
Hide
]
Use the Form facade when you need a simple field-name to field-value extraction flow.
Extract values from all AcroForm fields
- Open the PDF form document with the Form facade.
- Iterate through the field names from the Form facade and read each current field value into a map.
public static Map<String, String> getValuesFromAllFields(Path inputFile) {
Form form = new Form(inputFile.toString());
try {
Map<String, String> formValues = new LinkedHashMap<>();
for (String fieldName : form.getFieldNames()) {
formValues.put(fieldName, form.getField(fieldName));
}
System.out.println(formValues);
return formValues;
} finally {
form.close();
}
}