This brief tutorial guides on how to fill in a PDF form using Python. You will get guidance to set the environment, a step-wise process to write the application, and a runnable sample code to work with fillable PDF using Python. Information is also available to customize the PDF form fields’ appearance before saving it on the disk.
Steps to Fill PDF Form Fields using Python
- Set the IDE to use Aspose.PDF for Python via .NET to fill fields
- Load the source PDF file using the Document class having a fillable form in it
- Get a reference to the fields whose value is to be filled
- Set the new field data using the value property in the TextBoxField class
- Customize the field appearance if required
- Save the filled PDF on the disk
These steps encompass the complete process on how to fill up PDF form using Python. The process is quite simple where you need to load the source PDF file and get access to the target field in the fields collection of the PDF form. Once the field reference is available, set the field data using the value property along with setting the field appearance like its color and alignment, etc, if required.
Code to Fill in a PDF Form using Python
This code demonstrates how to fill out PDF using Python. It uses Document.form.fields collection to access the target text box field however you may also access other types of fields like button, check box, list box, and number field to name a few. Different properties of the form field like color and vertical alignment are set in this code whereas you can set its border, height, width, margin, etc. if required.
This article has taught us how to fill out PDF form using Python. If you want to learn the process of creating a new PDF file, refer to the article on how to create PDF in Python.