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.
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.
- Add a kind of field with FormEditor.AddField Method
- Use the FormEditor.Save Method to store all modifications.
// 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:
- New a object of Class FormFieldFacade and Class FormEditor, specify the Property FormEditor.Facade to the new object of Class FormEditor.
- Decorate the attributes of PDF Form Fields with Class FormFieldFacade.
- Call FormEditor.ResetFacade to clear all visual attribtues to empty value after decorating all attributes.
- Use the FormEditor.Save Method to store all modifications.
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:
- New a object of Class FormFieldFacade and Class FormEditor, specify the Property FormEditor.Facade to the new object of Class FormEditor.
- Decorate the attributes of PDF Form Fields with Class FormFieldFacade.
- Call FormEditor.ResetFacade to clear all visual attribtues to empty value after decorating all attributes.
- Use the FormEditor.Save Method to store all modifications.
// 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();
