Extract AcroForm - Extract Form Data from PDF in Java

Use the Form facade when you need a simple field-name to field-value extraction flow.

Extract values from all AcroForm fields

  1. Open the PDF form document with the Form facade.
  2. 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();
    }
}