Fill AcroForm - Fill PDF Form using Python
Contents
[
Hide
]
Fill Form Field in a PDF Document
The following example fills multiple fields in an existing PDF form by using the Form facade.
Use the following steps:
- Create a dictionary with field names and values.
- Bind the input PDF to a Form object.
- Iterate through available form fields.
- Fill fields that exist in the dictionary.
- Save the updated PDF.
import aspose.pdf as ap
def fill_form(input_file_name, output_file_name):
new_field_values = {
"First Name": "Alexander_New",
"Last Name": "Greenfield_New",
"City": "Yellowtown_New",
"Country": "Redland_New",
}
form = ap.facades.Form(input_file_name)
for field_name in form.field_names:
if field_name in new_field_values:
form.fill_field(field_name, new_field_values[field_name])
form.save(output_file_name)