IRONSOFTWAREHOME
PDF Forms

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

// #1 Use Case: Create a PDF Form from HTML Form Markup  
Path outputLocation = Paths.get("assets/BasicForm.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>";  
  
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();  
renderOptions.setCreatePdfFormsFromHtml(true);  
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"));
mvn install
PDF Forms

PDF Forms

This code example demonstrates how developers can use IronPDF to create and edit PDF documents with fillable forms.

To create PDF forms, simply create the form as desired using HTML markup, and convert it into PDF using one of IronPdf's available static rendering methods. Use PdfDocument.renderHtmlAsPdf to convert an HTML form marked up in a string of HTML (as shown in the example above), and use PdfDocument.renderHtmlFileAsPdf to convert an HTML file containing a form located on a local file path. Both methods will produce PDF forms that users can open and fill in using their preferred PDF reading applications.

By default, IronPDF will make any form within HTML markup editable. Developers can toggle this behavior on and off as needed by supplying a ChromePdfRenderOptions object along with the HTML content to a PDF rendering method. Set the createPdfFormsFromHtml property to true or false with the setCreatePdfFormsFromHtml method to enable or disable editable forms.

Reading and writing values to a PDF form's fields is achieved through its PdfDocument's FormManager. Reference it using the line of code below:

As shown on lines 26 and 29 of the code example, the developer can set values on form text fields directly by calling a FormManager's setFieldValue with the name of the text field (as specified in the associated <input> element name attribute of the original HTML markup), followed by the value with which it should be filled.

To read a form field's value, the developer must first get a direct reference to the desired form field through a FormManager's indexed list of FormField objects. The code below illustrates how this should be done:

Learn to Create PDF Forms in Java with IronPDF
View on GitHub

Ready to Get Started?

Version:2026.8just released

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.

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 IronPDF
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