IronPDF How-Tos Java Fill PDF Form How to Fill PDF Form in Java (Tutorial) Darrius Serrant Updated:July 28, 2025 Many people might expect to fill in a PDF field-by-field, but today we will focus instead on filling a PDF programmatically. A use case could arise when the application UI enhances the experience of the user, but it would need to be created with PDF files in an electronic format for archiving. After collating all data from user input, a librarian must create PDF forms programmatically. The filled-out documents are either saved for future use or modified. There are multiple Java PDF Libraries for PDF work, such as PDFBox, iText7, IronPDF, etc. In this article, we will explain how to use IronPDF to fill interactive forms. How to Fill PDF Form in Java Install Java library to fill PDF form Load existing PDF that contain form fields Select the form field of the loaded PDF with getForm method Use setFieldValue method to set the value to specified form field Export the PDF document IronPDF — a Java Library IronPDF is a Java PDF library for creating and editing PDFs that allows developers to easily create, edit, and manipulate PDF documents in their Java applications. The library is fully compatible with Java and can be integrated into any Java-based project with just a few lines of code. IronPDF provides a wide range of features, including support for text and image manipulation, document security, and digital signature capabilities. With IronPDF, developers can quickly and easily generate professional-quality PDF documents, making it a powerful tool for any Java-based project. Fill PDF Forms using IronPDF Let's take a look at how we can fill a PDF form programmatically using the Java PDF library. Install IronPDF in a Maven Project To install IronPDF Java via Maven, follow these steps: Open the pom.xml file in your project. Add the following dependencies within the <dependencies> tag. Save the pom.xml file and run mvn install in your project directory. This will install IronPDF Java and its dependencies in your project. You can get help from the Sonatype Central Repository Page for IronPDF. Now you can use IronPDF with your Java code. Using Java Code to Fill PDF Documents Programmatically The following code snippet demonstrates how to use the IronPDF library to create and fill PDF forms with Java using HTML markup. The code imports the necessary classes from the IronPDF library and uses the Paths.get method to specify the location where the resulting PDF form will be saved. import com.ironsoftware.ironpdf.PdfDocument; import com.ironsoftware.ironpdf.render.ChromePdfRenderOptions; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class App { // Main method to execute the program public static void main(String[] args) throws IOException { // Specify where the output PDF will be saved Path outputLocation = Paths.get("assets/BasicForm.pdf"); // HTML string which represents the form to be converted to PDF String formHTML = "<html>" + "<body>" + "<h2>Editable PDF Form</h2>" + "<form>" + "First name: <br> <input type='text' name='firstname' value=''> <br>" + "Last name: <br> <input type='text' name='lastname' value=''>" + "</form>" + "</body>" + "</html>"; // Set up PDF render options to create forms from HTML ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions(); renderOptions.setCreatePdfFormsFromHtml(true); // Render the HTML as a PDF and save it to the specified location PdfDocument.renderHtmlAsPdf(formHTML, renderOptions).saveAs(outputLocation); // #2 Use Case: Writing Values to the PDF Form PdfDocument form = PdfDocument.fromFile(outputLocation); // Set the value of the firstname input field form.getForm().setFieldValue("firstname", "Minnie"); // Set the value of the lastname input field form.getForm().setFieldValue("lastname", "Mouse"); // Save the changes to the PDF Form form.saveAs(Paths.get("assets/BasicForm_Filled.pdf")); } } import com.ironsoftware.ironpdf.PdfDocument; import com.ironsoftware.ironpdf.render.ChromePdfRenderOptions; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class App { // Main method to execute the program public static void main(String[] args) throws IOException { // Specify where the output PDF will be saved Path outputLocation = Paths.get("assets/BasicForm.pdf"); // HTML string which represents the form to be converted to PDF String formHTML = "<html>" + "<body>" + "<h2>Editable PDF Form</h2>" + "<form>" + "First name: <br> <input type='text' name='firstname' value=''> <br>" + "Last name: <br> <input type='text' name='lastname' value=''>" + "</form>" + "</body>" + "</html>"; // Set up PDF render options to create forms from HTML ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions(); renderOptions.setCreatePdfFormsFromHtml(true); // Render the HTML as a PDF and save it to the specified location PdfDocument.renderHtmlAsPdf(formHTML, renderOptions).saveAs(outputLocation); // #2 Use Case: Writing Values to the PDF Form PdfDocument form = PdfDocument.fromFile(outputLocation); // Set the value of the firstname input field form.getForm().setFieldValue("firstname", "Minnie"); // Set the value of the lastname input field form.getForm().setFieldValue("lastname", "Mouse"); // Save the changes to the PDF Form form.saveAs(Paths.get("assets/BasicForm_Filled.pdf")); } } JAVA The first block of code creates a PDF form by converting an HTML form marked up in a string of HTML using the PdfDocument.renderHtmlAsPdf method. The ChromePdfRenderOptions object is used to set the createPdfFormsFromHtml property to true, which makes the form within the HTML markup editable. The resulting PDF is then saved to the specified output location using the saveAs method. The second block of code demonstrates how to fill in the created PDF form. The PdfDocument.fromFile method is used to load the PDF form from the specified file path. The getForm method is then used to access the form fields, and the setFieldValue method is used to set the values of the firstname and lastname input fields. Finally, the changes are saved to a new file using the saveAs method. Output In the first block of code, IronPDF creates a basic PDF document with two form fields. Those form fields are text boxes. The document's PDF specification allows for input in the form fields. Here is the output: For the second block of code, set values in each text box or text field, and data is filled in each form field. Here is the screenshot of the filled PDF document: Summary In conclusion, IronPDF is a reliable and efficient library for working with PDF documents in Java. Its ability to programmatically fill PDF forms makes it a valuable tool for automating document processing tasks. IronPDF offers a free trial and affordable licensing options for IronPDF Java starting at $749, making it a cost-effective choice for businesses and developers. Frequently Asked Questions How can I fill PDF forms programmatically in Java? You can fill PDF forms programmatically in Java using IronPDF by loading the PDF document, accessing form fields with getForm, setting values using setFieldValue, and exporting the updated PDF. What are the benefits of using IronPDF for Java applications? IronPDF allows Java applications to efficiently create, edit, and manipulate PDF documents, with features like form filling, text and image manipulation, document security, and support for digital signatures. How do I install IronPDF in a Maven project? To install IronPDF in a Maven project, add the IronPDF dependencies to your pom.xml file under the tag and execute mvn install in the project directory to download and integrate the library. Can I create editable PDF forms from HTML using IronPDF? Yes, IronPDF can create editable PDF forms from HTML by using the renderHtmlAsPdf method and configuring the ChromePdfRenderOptions to make form fields editable. What is the role of the getForm method in IronPDF? The getForm method in IronPDF is used to access and manipulate form fields within a PDF document, enabling developers to programmatically set field values. Does IronPDF support digital signatures in PDFs? Yes, IronPDF supports adding digital signatures to PDF documents, enhancing document security and authenticity within Java applications. Is a free trial available for IronPDF? Yes, IronPDF offers a free trial as well as affordable licensing options, allowing developers to evaluate its capabilities before committing to a purchase. How can I ensure I don't lose formatting when filling PDF forms in Java? Using IronPDF, you can fill PDF forms without losing formatting by carefully setting form field values with setFieldValue and using the library's robust rendering and manipulation features. What is ChromePdfRenderOptions used for in IronPDF? The ChromePdfRenderOptions class in IronPDF is used to specify rendering options for PDFs, including setting properties to make forms editable and configuring other PDF rendering settings. Darrius Serrant Chat with engineering team now Full Stack Software Engineer (WebOps) Darrius Serrant holds a Bachelor’s degree in Computer Science from the University of Miami and works as a Full Stack WebOps Marketing Engineer at Iron Software. Drawn to coding from a young age, he saw computing as both mysterious and accessible, making it the perfect medium for creativity ...Read More Ready to Get Started? Free Maven Download View Licenses