How to Add Editable Field to PDF in Java

This tutorial guides us on how to add editable field to PDF in Java. It shares the detailed steps to write the application along with the resources required to set the development IDE for developing this application. A ready-to-run sample code is also accompanied that can be used to add fillable fields to PDF in Java using a few API calls in any environments supporting Java.

Steps to Add Editable Field to PDF in Java

  1. Set the development environment to use Aspose.PDF for Java to add form controls
  2. Instantiate the FormEditor class object to insert desired controls in the PDF
  3. Bind the target PDF file with the FormEditor class object for accessing control to it
  4. Add a field textbox on the target PDF page for filling in data
  5. Set the limit of the text that can be entered into this textbox control
  6. Save the resultant PDF file containing the form controls in it

Here are the brief steps on how to insert fillable fields in PDF in Java. The process is commenced by creating a FormEditor class object and then binding it with the target PDF file followed by calling the addField() method that requires the form field type, field name, PDF file page number, and the position and size on the page where this control is to be placed. For placing control over this newly added field, the setFieldLimit() method is called that sets the text limit for the textbox.

Code to Add Form Fields to PDF in Java

This source code demonstrates the operation to add fillable text box to PDF in Java. It uses the FormEditor class object that uses the FieldType.Text enumerator to describe the type of control to be added on the form however you may use other types like date time, numeric, image, barcode, radio, listbox, checkbox, and push button to name a few. The FormEditor can not only be used to add fields but can also be used to remove the fields, set visual attributes of the field, set the size of the fields, and even rename the fields if required.

This topic has introduced us to add fields to PDF in Java. If you want to learn the process to populate the PDF form with data from an Excel file, refer to the article on how to populate PDF form from Excel data in Java.

 English