How to Populate PDF Form from Excel Data in Java

This quick tutorial explains how to populate PDF form from Excel data in Java. It contains all the necessary details to configure the environment, detailed steps to load the template PDF file, methods to load and iterate through all the rows in the Excel file, and a runnable sample code that can be used for filling PDF form from Excel in Java. You will also learn the API calls to access any form field of your choice and then set its value with data from any row and column of the loaded XLSX file.

Steps to Fill PDF from Excel in Java

  1. Establish the environment to use Aspose.PDF and Aspose.Cells from the repository
  2. Load the source Excel file into the Workbook object containing the source data for PDF form
  3. Iterate through all the rows in the source Excel file
  4. Load the template PDF file into the Document class object and get access to the form fields in it
  5. Fill data in each form field from the desired column in each Excel row data
  6. Save each output PDF file with reference to the key data in the Excel row data

These steps populate PDF from Excel in Java such that first the source Excel file is loaded and then iteration is performed through all the desired rows in it to access the respective cell value. During the iteration, the template PDF file is loaded and its respective fields are accessed to set the values from the Excel file. In the same iteration, each filled PDF file is saved separately with reference to the current row in the iteration.

Code to Autofill PDF from Excel in Java

This code demonstrates the process to automatically fill PDF form from Excel data in Java by loading the Excel file into the Workbook class object that supports accessing each row and column of a worksheet and getting or setting values in it. On the other hand, the Document class provides options to load the template PDF file and get access to any of its fields using its name for accessing the values and saving the updated PDF file on the disk.

In this topic, we have learned the process to fill a PDF file with the data from an Excel file. If you want to learn the process to protect a PDF file with a password, refer to the article on how to protect PDF with password in Java.

 English