How to Create and Decorate Form Fields With API

Skip to end of metadata
Go to start of metadata
Create PDF Form Fields With API

Developers can utilize Class FormEditor to achieve PDF Form Fields in couple of simple steps. Currently Class FormEditor provides seven kinds of Fields defining in FieldType Enumeration, the following table illustrating details.

Member Name Description
Text Text type field
ComboBox ComboBox type field
ListBox ListBox type field
Radio Radio type field
CheckBox CheckBox type field
PushButton PushButton type field
InvalidNameOrType InvalidNameOrType type field

There are all three steps to create a PDF Form Field:

  • New a object of Class FormEditor specifying the name of original PDF document and the result PDF document.
[Java]
//  Open the document and create a Form object
FormEditor formEditor = new FormEditor(In_Template + "FormEditor.blank.pdf", OutPath + "added.pdf");

//  add a button field
formEditor.addField(FormEditor.FLDTYP_BTNFLD, "button1", "ButtonName", 1, new Rectangle(50, 50, 100, 20));

//  add a text field
formEditor.addField(FormEditor.FLDTYP_TXTFLD, "text1", "TextName", 1, new Rectangle(200, 50, 100, 20));

//  set items for a ComboBox
formEditor.setItems(new String[] { "123", "abc", "456" });
// add a combo box field
formEditor.addField(FormEditor.FLDTYP_COMBOBOX, "combobox1", "", 1, new Rectangle(50, 100, 100, 40));

//  add a check box field
formEditor.addField(FormEditor.FLDTYP_CHKBOX, "checkbox1", "", 1, new Rectangle(200, 100, 20, 20));

//set items for a list box
formEditor.setItems(new String[] { "123", "abc", "456" });
//  add a list field
formEditor.addField(FormEditor.FLDTYP_LIST, "list1", "", 1, new Rectangle(50, 200, 100, 20));

//  set items for a radio group
formEditor.setItems(new String[] { "1", "2", "3" });
//  add a radio button field
formEditor.addField(FormEditor.FLDTYP_RADIOBTN, "radio1", "", 1, new Rectangle(200, 200, 20, 20));

//  Close the document
formEditor.close();
 
Decorate PDF Form Fields With API

When create PDF Form Fields, developers can decorate fields at the same time to get a better effect of vision. Aspose.Pdf.Kit provides Class FormFieldFacade to achieve this goal. The attributes of a field that can be decorated are border style, width / border color, background color / font, font size / caption / text color, text alignment, text rotation. To get detail informations, please read the FormFieldFacade Members.
To use Class FormFieldFacade, developers should cooperater with Class FormEditor keeping with the following steps:

[Java]
//  Open the document and create a Form object
FormEditor formEditor = new FormEditor(In_Template + "blank.pdf", OutPath + " decorated.pdf");

//  create a FormFieldFacade to specify visual attributes
FormFieldFacade facade = new FormFieldFacade();

//  specify the facade properties
facade.setBorderColor(Color.red);
facade.setFontSize(10);
facade.setFont(FontStyle.Courier);
facade.setTextColor(Color.blue);
facade.setAlignment(FormFieldFacade.ALIGN_LEFT);

//  specify a facade object to the object of FormEditor.
formEditor.setFacade(facade);

//  add a button field
formEditor.addField(FormEditor.FLDTYP_BTNFLD, "button1", "A Button", 1, new Rectangle(200, 400, 100, 20));

//  clear the settings
formEditor.resetFacade();

//  Close the document
formEditor.close();
 
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.