How to Fill Form Fields With API

Skip to end of metadata
Go to start of metadata
Aspose.Pdf.Kit.Form is the simplest abstraction of a PDF Form by Aspose Pty Ltd. that provides a mean to fill the PDF Form Fields programmatically. In this section, some basic information of how to fill in many types of fields will be provided. All the information is based on a template PDF student.pdf. It is a student form about a student's personal information. It includes every common type of fields. So it's enough to complete your basic literal field operation.

A complete source code that demostrates the use of Aspose.Pdf.Kit.Form to fill in the PDF Form Fields can be found as Simple Example in Java.

Description of Sample Template PDF

The template PDF student.pdf includes seven fields. Their properties which are set when they are created in Adobe or other tools are listed at the follwing:

Field Name Field Type Export value(Choice value)
Name Text Field  
Gender Radio Group Field Male/Female
Telephone Text Field  
Address Text Field  
Grade Combo Field GradeOne/GradeTwo/GradeThree/GradeFour
Lodging Check Field Yes/Off
Photo Button Field  
How to fill in a Text Field

Fill the Text Field with field name "Name" with the value "Mike".Note: Both, the Field Name and Value are Case Sensitive.

[Java]
//Instantiating Aspose.Pdf.Kit.Form object giving input and output PDF files as input
Form form = new Form("student.pdf", "output.pdf");

//Filling a Text Field (Name)
form.setField("Name", "Mike");
 
How to fill in a Radio Group Field

Fill the Radio Group Field with field name "Gender" with the value "Male". The value must be one of the Export value of the field when it be created in the Adobe. And the radio group fields should have the same field name when they are created.Note: Both, the Field Name and Value are Case Sensitive.

[Java]
//Instantiating Aspose.Pdf.Kit.Form object giving input and output PDF files as input
Form form = new Form("student.pdf", "output.pdf");

//Choose "Male"
form.setField("Gender", "Male");

//OR Choose "Female"
form.setField("Gender", "Female");
 
How to fill in a Combo Box Field

Fill the Combo Box Field with field name "Grade" with the value "GradeTwo". The value must be one of the Export value of the field when it be created in the Adobe.Note: Both, the Field Name and Value are Case Sensitive.

[Java]
//Instantiating Aspose.Pdf.Kit.Form object giving input and output PDF files as input
Form form = new Form("student.pdf", "output.pdf");

//Filling the Combo Box Field with value "GradeTwo"
form.setField("Grade", "GradeTwo");
 
How to fill in a Check Box Field

Fill the Check Box Field with field name "Lodging" with the value "Off". It means uncheck the check box. When the check box is created, the default export value of check and uncheck is "Yes" and "Off". So you can only set the two values to the field. The value must be one of the Export value of the field when it be created in the Adobe.Note: Both, the Field Name and Value are Case Sensitive.

[Java]
//Instantiating Aspose.Pdf.Kit.Form object giving input and output PDF files as input
Form form = new Form("student.pdf", "output.pdf");

//Uncheck the check box
form.setField("Lodging", "Off");

// OR Check the check box
form.setField("Lodging", "Yes");
 
How to fill in an Image Button Field

At first created a button field in Adobe Acrobat. Note that the button's length and size should be near to the image's. Otherwise the image will be auto fit to the button's bound and the visual effect may be not very good.

[Java]
//Instantiating Aspose.Pdf.Kit.Form object giving input and output PDF files as input
Form form = new Form("student.pdf", "output.pdf");

//Filling the Image Button Field
form.fillImageField("Photo","lovely.jpg");
 
How to fill in List Field

There is no List Field in the template, but the usage is the same as the Combo Box excluding different face.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.