IRONSOFTWAREHOME

How to Fill PDF Form in Java (Tutorial)

Curtis Chau
Curtis Chau
Updated: August 2, 2026

IronPDF enables Java developers to programmatically fill PDF forms by loading existing PDFs, accessing form fields with getForm(), setting values with setFieldValue(), and saving the filled document. This makes it straightforward to automate document processing in business applications.

Quickstart: Fill PDF Form in Java
// 1. Add IronPDF dependency to your Maven project
// 2. Load your PDF form
PdfDocument form = PdfDocument.fromFile("form.pdf");
// 3. Fill form fields
form.getForm().setFieldValue("firstname", "John");
// 4. Save the filled PDF
form.saveAs(Paths.get("filled_form.pdf"));
Text

This article covers how to fill PDF forms programmatically in Java. A common scenario is when an application collects user data through a UI that must be persisted in PDF format for archiving, compliance, or downstream processing.

After user input is captured, applications often need to inject that data directly into pre-existing PDF templates. Multiple Java PDF libraries handle this task, including Apache PDFBox, iText, and IronPDF. This guide explains how to use IronPDF to fill interactive forms with text fields, checkboxes, radio buttons, and dropdown lists. For developers building related document workflows, see the guide on creating PDF forms from scratch in Java.

What Is IronPDF for Java?

IronPDF is a Java PDF library for creating, editing, and manipulating PDF documents. It integrates into any Maven-based Java project and exposes a clean API that makes common PDF tasks achievable with minimal boilerplate.

The library covers the full PDF lifecycle: rendering HTML to PDF, reading and writing form data, adding digital signatures, applying security settings, compressing documents, and printing. For working with forms specifically, IronPDF gives programmatic access to every field type in a PDF document while preserving the original formatting. This makes it well-suited for batch form processing, pre-populating templates with database records, or wiring form-filling into a larger Java workflow. See the IronPDF Java API reference for a full list of available classes and methods.

How Do I Install IronPDF in a Maven Project?

Add the following dependency block to your pom.xml file to install IronPDF for Java.

Open pom.xml and insert the dependency inside the <dependencies> element, then run mvn install to download the library. Available versions are listed on Maven Central.

<dependency>
    <groupId>com.ironsoftware</groupId>
    <artifactId>ironpdf</artifactId>
    <version>2024.9.1</version>
</dependency>
XML

After installation, import com.ironsoftware.ironpdf.PdfDocument and com.ironsoftware.ironpdf.render.ChromePdfRenderOptions in your Java class to access the form-filling API. For deployment guidance on cloud platforms, see the guides for AWS, Azure, and Google Cloud.

Tips: When working with IronPDF in a Docker or containerized environment, set the IronPdf.licenseKey system property before the first PdfDocument call to avoid license verification delays at runtime.

How Do I Create and Fill a PDF Form Using HTML in Java?

The most reliable way to produce a consistently structured, fillable PDF is to define the form in HTML and render it with IronPDF. The library converts HTML <input> elements directly into interactive PDF form fields.

The following code creates a two-field PDF form from an HTML string and then fills both fields:

import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.render.ChromePdfRenderOptions;
import java.io.IOException;
import java.nio.file.Paths;

public class App {

    public static void main(String[] args) throws IOException {

        // Define an HTML form with two text input fields
        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>";

        // Enable HTML-to-form-field conversion during rendering
        ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();
        renderOptions.setCreatePdfFormsFromHtml(true);

        // Render HTML to PDF and save the blank template
        PdfDocument.renderHtmlAsPdf(formHTML, renderOptions)
            .saveAs(Paths.get("assets/BasicForm.pdf"));

        // Load the template and fill in field values
        PdfDocument form = PdfDocument.fromFile(Paths.get("assets/BasicForm.pdf"));
        form.getForm().setFieldValue("firstname", "Minnie");
        form.getForm().setFieldValue("lastname", "Mouse");

        // Save the completed form to a new file
        form.saveAs(Paths.get("assets/BasicForm_Filled.pdf"));
    }
}
Java

The first block uses ChromePdfRenderOptions with setCreatePdfFormsFromHtml(true) to tell the rendering engine to treat HTML <input> elements as live PDF form fields rather than static text. The rendered PDF is saved as a reusable template. The second block loads that template, calls getForm().setFieldValue() for each field by name, and writes the result to a separate output file, leaving the original template untouched for future use.

What Does the Output Look Like?

The first rendering produces a PDF with two empty text fields, fully editable in any PDF reader.

Simple PDF form showing editable first name and last name text input fields with blue outlined boxes, rendered by IronPDF from HTML

After setFieldValue() runs, both fields are populated with the supplied data:

IronPDF Java output: PDF form with "Minnie" in the First name field and "Mouse" in the Last name field, showing successfully filled form data

How Do I Fill an Existing PDF Form That I Did Not Create?

Many real-world workflows receive third-party PDF templates (government forms, insurance documents, vendor contracts) that already contain named fields. Loading and filling these is the same process: use PdfDocument.fromFile() to load the document, then getForm().setFieldValue() to set each field by its name.

import com.ironsoftware.ironpdf.PdfDocument;
import java.io.IOException;
import java.nio.file.Paths;

public class FillExistingForm {

    public static void main(String[] args) throws IOException {

        // Load a third-party fillable PDF
        PdfDocument form = PdfDocument.fromFile(Paths.get("templates/application.pdf"));

        // Set text field values by field name
        form.getForm().setFieldValue("applicant_name", "Jane Smith");
        form.getForm().setFieldValue("date_of_birth", "1985-06-14");
        form.getForm().setFieldValue("reference_number", "REF-2024-00421");

        // Save the completed application
        form.saveAs(Paths.get("output/application_filled.pdf"));
    }
}
Java

To discover field names in an existing PDF, open the document in Adobe Acrobat Reader, right-click any field, and select "Properties". The field name appears in the General tab. Alternatively, iterate over all fields programmatically:

import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.form.FormField;
import java.nio.file.Paths;

public class ListFormFields {

    public static void main(String[] args) throws Exception {

        PdfDocument form = PdfDocument.fromFile(Paths.get("templates/application.pdf"));

        // Print the name and type of every form field
        for (FormField field : form.getForm().getFields()) {
            System.out.println("Field: " + field.getName()
                + " | Type: " + field.getType());
        }
    }
}
Java

Printing field names before writing data prevents setFieldValue() from silently failing on a mismatched name. Field names in PDF documents are case-sensitive, so "firstname" and "FirstName" are treated as different fields.

Please note: IronPDF's getForm().getFields() returns a list of FormField objects. Each exposes getName(), getType(), and getValue(). These are useful when building dynamic form-fill routines that read field names from an external data source such as a database or CSV file.

How Do I Fill Checkboxes and Radio Buttons in Java?

Text fields accept string values directly, but checkboxes and radio buttons require specific exported values that the PDF defines at authoring time. Use setFieldValue() with the correct export value string for each field.

import com.ironsoftware.ironpdf.PdfDocument;
import java.nio.file.Paths;

public class FillCheckboxesAndRadio {

    public static void main(String[] args) throws Exception {

        PdfDocument form = PdfDocument.fromFile(Paths.get("templates/survey.pdf"));

        // Check a checkbox by setting its exported value (often "Yes" or "On")
        form.getForm().setFieldValue("agree_terms", "Yes");

        // Select a radio button option by its exported value
        form.getForm().setFieldValue("preferred_contact", "email");

        form.saveAs(Paths.get("output/survey_filled.pdf"));
    }
}
Java

The export value for a checkbox is typically "Yes", "On", or a custom string set by the form author. For radio button groups, each option in the group shares the same field name but has a unique export value. Use the field-listing technique from the previous section to confirm the exact export values before writing automated fill routines.

Important: If setFieldValue() does not appear to check a checkbox or select a radio button, the export value string is likely wrong. List the field with getFields() and inspect getValue() on a manually checked copy of the PDF to retrieve the correct string.

How Do I Fill Dropdown Lists in a PDF Form Using Java?

Dropdown list fields (also called combo box fields) use the same API as text fields. Pass the option's export value as a string to setFieldValue(). The export value is typically the visible option text unless the form author defined a separate underlying value.

import com.ironsoftware.ironpdf.PdfDocument;
import java.nio.file.Paths;

public class FillDropdown {

    public static void main(String[] args) throws Exception {

        PdfDocument form = PdfDocument.fromFile(Paths.get("templates/registration.pdf"));

        // Set a dropdown/combo box field to a specific option
        form.getForm().setFieldValue("country", "United States");

        // Set a list box field (multi-select may require comma-separated values)
        form.getForm().setFieldValue("subscription_tier", "Professional");

        form.saveAs(Paths.get("output/registration_filled.pdf"));
    }
}
Java

When the dropdown export value differs from the visible label, use getFields() to inspect the field's available options. Passing a value that does not match any option in the field's definition leaves the selection unchanged without throwing an exception, so validating export values before a batch run avoids silent data loss.

Tips: To inspect all available options for a combo box, cast the FormField to FormComboBoxField and call getOptions(). This returns the list of valid export values for that dropdown.

How Do I Flatten a Filled PDF Form in Java?

Flattening converts all form fields into static, non-editable content. This prevents recipients from altering submitted data and is required for many archival and compliance use cases. IronPDF supports form flattening as part of its PDF manipulation capabilities.

import com.ironsoftware.ironpdf.PdfDocument;
import java.nio.file.Paths;

public class FlattenForm {

    public static void main(String[] args) throws Exception {

        PdfDocument form = PdfDocument.fromFile(Paths.get("assets/BasicForm_Filled.pdf"));

        // Flatten all form fields -- values become static text
        form.getForm().flatten();

        form.saveAs(Paths.get("output/BasicForm_Archived.pdf"));
    }
}
Java

After flatten() runs, no interactive form fields remain in the output PDF. The document size typically decreases because the form field overlay layers are removed. Flattened PDFs are safe to distribute without risk of recipients editing the submitted values.

What Are the Next Steps for PDF Form Filling in Java?

IronPDF provides a focused, low-boilerplate API for filling PDF forms in Java. The getForm() method gives direct access to text fields, checkboxes, radio buttons, and dropdown lists. When archival is required, flatten() locks all filled data as static content.

For the next stages of your PDF document workflow, explore these guides:

Start a free trial of IronPDF for Java to test form filling in your own project. When you are ready to deploy, view IronPDF licensing options to find a plan that fits your team's needs.

Frequently Asked Questions

What is IronPDF for Java?

IronPDF is a Java PDF library designed for creating, editing, and manipulating PDF documents. It offers a clean API for tasks such as form filling, rendering HTML to PDF, reading and writing form data, adding digital signatures, and applying security settings.

How can I fill PDF forms in Java using IronPDF?

To fill PDF forms in Java with IronPDF, load the PDF using PdfDocument.fromFile(), access the form fields with getForm(), set field values using setFieldValue(fieldName, value), and save the filled document with saveAs().

Can IronPDF handle existing PDF forms not created by me?

Yes, IronPDF can fill existing PDF forms by loading them using PdfDocument.fromFile(), accessing the fields with getForm(), and setting field values using setFieldValue() for each named field.

How do I install IronPDF in a Maven project?

Install IronPDF by adding the specified dependency block to your pom.xml file under and running mvn install to download the library from Maven Central.

How does IronPDF convert HTML forms to PDF?

IronPDF can render HTML to PDF, converting HTML elements directly into interactive PDF form fields using ChromePdfRenderOptions with setCreatePdfFormsFromHtml(true).

How do I fill checkboxes and radio buttons in a PDF form using Java?

Checkboxes and radio buttons require specific exported values to be set with setFieldValue(). For checkboxes, this is often 'Yes' or 'On', while radio buttons require the unique exported value for the selected option.

How can I fill dropdown lists in a PDF form using IronPDF?

Use setFieldValue() to assign the dropdown option's export value. The exact export value should match the option's defined value in the PDF form, with FormComboBoxField.getOptions() providing the list of valid values.

How do I flatten a filled PDF form using IronPDF?

Flattening a filled PDF form with IronPDF can be done by calling form.getForm().flatten() on the PdfDocument, which converts form fields into static text, preventing further editing.

What are some additional features of IronPDF for Java?

Beyond form filling, IronPDF features include rendering HTML to PDF, manipulating PDF security settings, applying digital signatures, and allowing programmatic access to various PDF document elements.

How can I find more resources to further explore IronPDF capabilities?

Explore the [IronPDF Java API reference](https://ironpdf.com/java/object-reference/api/) for detailed documentation, and additional guides on creating forms from HTML, HTML to PDF conversion, and PDF security and digital signing.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Version:2026.8just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
Java Maven Library for PDF
Install with Maven

Version: 2026.8

<dependency>
   <groupId>com.ironsoftware</groupId>
   <artifactId>ironpdf</artifactId>
   <version>2026.8.2</version>
</dependency>
https://central.sonatype.com/artifact/com.ironsoftware/ironpdf/2026.8.2
or
Java PDF JAR
Download JAR

Version: 2026.8

Manually install into your project

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
Java Maven Library for PDF
Install with Maven

Version: 2026.8

<dependency>
   <groupId>com.ironsoftware</groupId>
   <artifactId>ironpdf</artifactId>
   <version>2026.8.2</version>
</dependency>
https://central.sonatype.com/artifact/com.ironsoftware/ironpdf/2026.8.2
or
Java PDF JAR
Download JAR

Version: 2026.8

Manually install into your project