Extract AcroForm - Extract Form Data from PDF in Python

Extract Data from Form

Get Values from All Fields in a PDF Document

To read values from all fields in a PDF document, iterate through the form field names and retrieve each value from the Form facade.

Use the following steps:

  1. Bind the input PDF to a Form object.
  2. Iterate through field_names.
  3. Read each value with get_field().
  4. Store values in a dictionary.
  5. Return or process the extracted values.

The following Python code snippet shows this approach.

import aspose.pdf as ap


def get_values_from_all_fields(input_file_name):
    form = ap.facades.Form(input_file_name)

    form_values = {}
    for field_name in form.field_names:
        form_values[field_name] = form.get_field(field_name)

    print(form_values)
    return form_values