Extract AcroForm - Extract Form Data from PDF in Python
Contents
[
Hide
]
Extract data from form
Get Values from all the Fields of PDF Document
To get values from all the fields in a PDF document, you need to navigate through all the form fields and then get the value using the Value property. Get each field from the Form collection, in the base field type called Field and access its value property.
The following Python code snippets show how to get the values of all the fields from a PDF document.
import aspose.pdf as ap
# Construct the full path to the input PDF file
data_dir = "/path/to/your/pdf/files/"
path_infile = os.path.join(work_dir, infile)
# Create a Form object from the PDF file
form = ap.facades.Form(path_infile)
# Initialize an empty dictionary to store form values
form_values = {}
# Iterate through all form fields in the PDF
for formField in form.field_names:
# Retrieve the value for each form field and store in the dictionary
form_values[formField] = form.get_field(formField)
# Print and return the extracted form values
print(form_values)