As easy as 1, 2, 3...
Since the introduction of Version 6 of the API, the jPDF
Template has allowed the creation of form fields in PDF documents, thus
allowing us to provide an all-in-one solution for form field processing.
To create a new form field in a document you will need the following information:
- A unique name for the new form field.
- The index of the page where it should be created.
- The position and dimensions of this form field in the designated page.
In the example below, we will create a form field with the following attributes:
- A text form field with the name "My New TextField" on the first page of an existing document.
- The Top Left Corner of the form field will be positioned as the coordinate x=10 and y=10 on the page.
- It will have a size of 100 by 40.
// Open the template document:
PdfDocument doc = new PdfDocument("mydocument.pdf");
// Create a rectangle with the position and dimensions of the form fields:
Rectangle rect = new Rectangle(10, 10, 100, 40);
// Create the form fields module:
TextField field = TextField.createInstance(doc, "My New TextField", 1, rect);
TemplateModule template = doc.getTemplateModule();
As you can see, the creation of form fields is quite simple.
The only process remaining is the setting of the value of this new
form field and the saving of the document, as with the other tutorials
in this section.