Extract AcroForm - Extract Form Data from PDF in Python
Contents
[
Hide
]
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:
- Bind the input PDF to a
Formobject. - Iterate through
field_names. - Read each value with
get_field(). - Store values in a dictionary.
- 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