This short article guides on how to fill PDF form from Excel using Python. It provides and introduction to open PDF and Excel files and then filling PDF form from Excel using Python. It contains methods and properties to access the PDF Form fields and on the other hand, get data from a cell in a particular worksheet of the loaded Excel file.
Steps to Autofill PDF from Excel using Python
- Set the development environment to use Aspose.PDF for Python via .NET and Aspose.Cells for Python via .NET
- Load the source PDF file using the Document class object having form fields
- Load the source Excel file using the Workbook object
- Get the reference to the target field in the form of the PDF document
- Get the reference to the first worksheet and the target cell in it
- Set the textbox field value with the selected cell
These steps present the process to populate PDF form from Excel using Python in an easier way where both the PDF and Excel files are loaded and the particular textbox field of a form is accessed. Similarly, the target worksheet and a particular cell in it are obtained thereafter it is filled in the PDF form textbox field.
Code to Fill in PDF from Excel using Python
This code demonstrates the process to automatically fill PDF form from Excel data using Python. It shows that the Document class of aspose.pdf can be used to load the PDF and aspose.cells.Workbook class for loading the Excel file for transferring data. You can access the form fields by providing the index of the target PDF form field using the Document.form.fields collection and the target cell is accessed by selecting the target worksheet in the aspose.cells.Workbook.worksheets collection.
This article has taught us to autofill PDF form from Excel using Python. If you want to learn the process to insert a table in PDF, refer to the article on how to insert table in PDF using Python.