Fill, Create, or Edit Fillable PDF Forms Programmatically using Java

Fill PDF Form Java

In these modern times, a lot of data is collected using forms and fillable PDF forms are worth mentioning in this context. They are an efficient way of collecting and arranging information. Moreover, fillable PDF forms are now being used as a standard by different institutions. For instance, some court of law, or a procurement firm can efficiently use fillable PDF forms to standardize their procedures. For creating such applications, Aspose.PDF for Java API is the most suitable API. Curious to know why? Let us explore the following use cases where we will be working with PDF forms programmatically.

Installation

You can head to New Releases section where you can configure the API to enrich your Java applications and enabling them to process PDF documents, or you can define the dependency in your Maven application as under:

Repository

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository

Dependency

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-pdf</artifactId>
    <version>20.7</version>
</dependency>

After successfully configuring the API, let us move on to following uses cases:

Create Fillable PDF Forms using Java

You can create fillable PDF form in Java applications by following the steps below:

  1. Create a PDF file with a blank page
  2. Add TextBox field and RadioButton field on the page
  3. Save the output PDF file

The code snippet below shows how to create a fillable PDF form from scratch using Java:

Fill, Modify, or Delete Form Fields in Existing PDF using Java

We have learned to create a new fillable PDF file from scratch. Let us proceed to scenarios where existing PDF documents are processed:

i) Fill a Form Field in Existing PDF file using Java

Like we have created the PDF form in the above example, let us proceed with the same document and fill the form fields programmatically using Java. You can fill the created form with below steps:

  1. Load input file
  2. Fill values in the TextBox field
  3. Fill RadioButton fields by selecting an option
  4. Save out PDF form

The code snippet below shows how to fill fillable forms using Java:

ii) Modify a Form Field in PDF Document using Java

Sometimes we need to edit or update field values in a PDF form. You can easily edit a fillable PDF form with below steps:

  1. Initialize input PDF
  2. Get a reference to the form field by its name
  3. Edit the PDF form
  4. Save edited PDF form

The code snippet below shows how to update or edit a fillable PDF file using Java:

iii) Delete a Form Field in Existing PDF File using Java

You can remove or delete a form field easily in your Java applications. You can follow the steps below:

  1. Initialize a PDF form
  2. Delete the form field using its name
  3. Save updated PDF form

Below code snippet shows how to delete a form field from PDF form using Java:

Preserve Extended Rights of PDF Forms using Java

You may notice that some PDF forms have extended rights. They are used to avoid modifications in original content and only filling of forms is allowed. Extended rights of PDF files can be affected when

You fill such a form and save it in different locations of the disk. Therefore, we need to save such files incrementally with below steps:

  1. Initialize PDF form
  2. Fill in the fields
  3. Save the filled PDF document

The code snippet below shows how to preserve extended rights while filling PDF form, using Java:

Use JavaScript in PDF Form using Java

You can fill the fillable PDF form fields using Javascript with Aspose.PDF for Java. You should follow the following steps :

  1. Load PDF document
  2. Add a field on specific page location
  3. Set JavaScript and open action for the document Save PDF file

Following code snippet shows how to use JavaScript in fillable PDF forms:

Conclusion

We have learned how to create fillable PDF forms, as well as filling or editing the form fields using the Java environment. Moreover, we have also explored preserving the extended rights in PDF documents in addition to using JavaScript on a PDF document action. In case of any concerns or issues, please feel free to contact us at Free Support Forum.

See Also

Create, Fill, or Edit Fillable PDF Forms Programmatically with C#