Fillable PDF Forms via Python

Сreate fillable PDF acroforms. Use Aspose.PDF for Python for .NET to modify PDF files programmatically

How to Fill PDF Forms Using Python for .NET Library

In order to fill PDF Forms (Acroforms) in a PDF file, we’ll use Aspose.PDF for Python via .NET API, which is feature-rich, powerful, and easy-to-use document manipulation API for Python app. You can download its latest version directly from PyPi package manager, search for aspose-pdf and install. You may also use the following command from the console or terminal.

How to Fill AcroForm in PDF using Python


You need Aspose.PDF for .NET to try the code in your environment.

  1. Load PDF in an instance of Document class.
  2. Create a field in PDF file.
  3. Add field to the document.
  4. Save modified PDF

Fill AcroForm in PDF - Python

This sample code shows how to Fill PDF forms in PDF using Python

import aspose.pdf as apdf

from os import path

path_infile = path.join(self.data_dir, infile)
path_outfile = path.join(self.data_dir, outfile)

# Define the new field values
new_field_values = {
    "First Name": "Alexander_New",
    "Last Name": "Greenfield_New",
    "City": "Yellowtown_New",
    "Country": "Redland_New",
}

# Create a Form object from the input PDF file
form = apdf.facades.Form(path_infile)

# Fill out the form fields with the new values
for formField in form.field_names:
    if formField in new_field_values:
        form.fill_field(formField, new_field_values[formField])

# Save the modified form to the output PDF file
form.save(path_outfile)