Interactive Forms

An interactive form, sometimes referred to as an AcroForm, is a collection of fields for gathering information interactively from the user. A PDF document may contain any number of fields, appearing on any combination of pages, all of which make up a single, global interactive form spanning the entire document.

FormElement

The FormElement class is parent to the following derived classes: Button, CheckBox, ChoiceField, ComboBox, ListBox, RadioButton, Signature, and TextField.

::important

Do not confuse the FormElement class with the FormField class and its child classes!

Properties

Property Description
BackgroundColor Gets or Sets the fill/background color of a form field.
BorderColor Gets or Sets the border color of a form field.
BorderStyle Gets or Sets the BorderStyle .
Height Gets or Sets the height of a form field.
ID Gets or sets the ID of the page element. (Inherited from PageElement)
IgnoreMargins Gets or sets ignore margin property. Setting False will consider the margin while placing the page element based on the RelativeTo property. (Inherited from PageElement)
MappingName Gets or Sets an mapping name, of a form field.
Name Gets or Sets the name of a form field.
Output Gets or sets output options for the field.
Printable Gets or Sets the form field printable on Pdf. By default it is True.
ReaderEvents Gets the reader events of the annotation.
ReadOnly Gets or Sets the read only property status of the form field.
RelativeTo Gets and sets placement of the page element on the page. (Inherited from PageElement)
Rotate Gets or Sets the angle of a form field. Rotation angle should be multiple of 90, default is 0.
Tag Gets or sets the structure element of the form element.
TagOrder Gets or sets the tag order of the taggable element. (Inherited from TaggablePageElement)
TextColor Gets or Sets the color of the text for the field.
ToolTip Gets or Sets an alternate field name, of a form field.
Visible Gets or Sets the form field visible on Pdf. By default its True.
Width Gets or Sets the width of a form field.
X Gets or Sets the X coordinate of a form field.
Y Gets or Sets the Y coordinate of a form field.

Field Types

Interactive forms support the following field types.

Field Description
Button Button fields represent interactive controls on the screen a user can click. They include push buttons, check boxes, and radio buttons.
TextField Text fields are boxes or spaces in which the user can enter text from the keyboard.
CheckBox Check Box fields are interactive controls that a user can toggle between.
RadioButton Radio Button fields are a set of related toggles that at most one can be selected.
Choice fields (ListBox and ComboBox) Choice fields contain several text items; only one value may be selected at a time. They include scrollable list boxes and combo boxes.
Signature Signature fields are boxes or spaces in which a digital signature can be placed.

Form field content can be validated for formatting or for auto filling values with JavaScript using AnnotationReaderEvents. Please refer to the JavaScript topic for more information.

Button

A Button inherits the FormElement parent class's properties. This example shows how to create a Button and add it to the page.

Button button = new Button( "Button Name", 50, 50, 100, 50 );
button.Action = new JavaScriptAction( "app.alert('Hello');" );
button.BackgroundColor = RgbColor.AliceBlue;
button.Behavior = Behavior.CreatePush( "downLabel", "rolloverLabel" );
button.BorderColor = RgbColor.BlueViolet;
button.BorderStyle = BorderStyle.Beveled;
button.Label = "Push";
button.TextColor = RgbColor.DarkGreen;
button.ToolTip = "Click";       
Dim MyButton As Button = New Button("Button Name", 50, 50, 100, 50)
MyButton.Action = New JavaScriptAction( "app.alert('Hello');" )
MyButton.BackgroundColor = RgbColor.AliceBlue
MyButton.Behavior = Behavior.CreatePush( "downLabel", "rolloverLabel" )
MyButton.BorderColor = RgbColor.BlueViolet
MyButton.BorderStyle = BorderStyle.Beveled
MyButton.Label = "Push"
MyButton.TextColor = RgbColor.DarkGreen
MyButton.ToolTip = "Click"

Refer to the Button API documentation for a complete example.

CheckBox

The CheckBox element is a child class of the FormField class. The following example illustrates adding a CheckBox to the page.

CheckBox checkBox = new CheckBox( "Check Box Name", 5, 7, 50, 50 );
checkBox.DefaultChecked = true;
checkBox.ToolTip = "Check it";        
Dim MyCheckBox As CheckBox = New CheckBox( "Check Box Name", 5, 7, 50, 50 )
MyCheckBox.DefaultChecked = true
MyCheckBox.ToolTip = "Check it" 

Refer to CheckBox API for a complete example.

ComboBox

The ComboBox element is child class of ChoiceField, which is a child of FormElement. This example shows how to create a ComboBox and add it to a page.

ComboBox comboBox = new ComboBox( "Combo Box Name", 50, 75, 150, 25 );
comboBox.Items.Add( "One", true );
comboBox.Items.Add( "Two" );
comboBox.Items.Add( "Three" );
comboBox.BackgroundColor = RgbColor.AliceBlue;
comboBox.BorderColor = RgbColor.DarkMagenta;
comboBox.Editable = true;
comboBox.ToolTip = "Select";        
Dim MyComboBox As ComboBox = New ComboBox( "Combo Box Name", 50, 75, 150, 25 )
MyComboBox.Items.Add( "One",true )
MyComboBox.Items.Add( "Two" )
MyComboBox.Items.Add( "Three" )
MyComboBox.BackgroundColor = RgbColor.AliceBlue
MyComboBox.BorderColor = RgbColor.DarkMagenta
MyComboBox.Editable = True
MyComboBox.ToolTip = "Select"  

Refer to the ComboBox API documentation for a complete example.

ListBoxField

The ListBox is a child class of the ChoiceField, which is in turn a child of FormField. This example shows how to create a ListBox and add it to a page.

ListBox listBox = new ListBox( "List Box Name", 5, 2, 100, 150 );
listBox.Items.Add( "One",true );
listBox.Items.Add( "Two",true );
listBox.Items.Add( "Three" );
listBox.BackgroundColor = RgbColor.AliceBlue;
listBox.BorderColor = RgbColor.DarkMagenta;
listBox.BorderStyle = BorderStyle.Dashed;
listBox.Multiselect = true;
listBox.ToolTip = "Select";        
Dim MyListBox As ListBox = New ListBox( "List Box Name", 5, 2, 100, 150 )
MyListBox.Items.Add( "One",true )
MyListBox.Items.Add( "Two",true )
MyListBox.Items.Add( "Three" )
MyListBox.BackgroundColor = RgbColor.AliceBlue
MyListBox.BorderColor = RgbColor.DarkMagenta
MyListBox.BorderStyle = BorderStyle.Dashed
MyListBox.Multiselect = True
MyListBox.ToolTip = "Select"   

Refer to the ListBox API documentation for a complete example.

RadioButton

The RadioButton class inherits from the FormElement class. This example shows how to create a RadioButton and add it to the page.

RadioButton radio1 = new RadioButton( "Radio Button Name", 50, 25, 100, 75 );
radio1.DefaultChecked = true;
radio1.ExportValue = "abc";
radio1.ToolTip = "first";
RadioButton radio2 = new RadioButton( "Radio Button Name", 50, 140, 100, 75 );
radio2.ExportValue = "def";
radio2.ToolTip = "second";
RadioButton radio3 = new RadioButton( "Radio Button Name", 50, 250, 100, 75 );
radio3.ExportValue = "ghi";
radio3.ToolTip = "third";        
Dim MyRadio1 As RadioButton = New RadioButton( "Radio Button Name", 50, 25, 100, 75 )
MyRadio1.DefaultChecked = true
MyRadio1.ExportValue = "abc"
MyRadio1.ToolTip = "first"
Dim MyRadio2 As RadioButton = New RadioButton( "Radio Button Name", 50, 140, 100, 75 )
MyRadio2.ExportValue = "def"
MyRadio2.ToolTip = "second"
Dim MyRadio3 As RadioButton = New RadioButton( "Radio Button Name", 50, 250, 100, 75 )
MyRadio3.ExportValue = "ghi"
MyRadio3.ToolTip = "third"  

Refer to the RadioButton API documentation for a complete example.

Text Form Field

A TextField is a child class of FormElement. This example shows how to create a TextField and add it to a page.

TextField textField = new TextField( "Text Field Name", 50, 75, 150, 100 );
textField.TextAlign = Align.Center;
textField.BackgroundColor = RgbColor.AliceBlue;
textField.BorderColor = RgbColor.DeepPink;
textField.Font = Font.TimesItalic;
textField.FontSize = 16.0f;
textField.TextColor = RgbColor.Brown;
textField.DefaultValue = "ceTe Software";
textField.MultiLine = true;
textField.ToolTip = "Text";        
Dim MyTextField As TextField = New TextField( "Text Field Name", 50, 75, 150, 100 )
MyTextField.TextAlign = Align.Center
MyTextField.BackgroundColor = RgbColor.AliceBlue
MyTextField.BorderColor = RgbColor.DeepPink
MyTextField.Font = Font.TimesItalic
MyTextField.FontSize = 16.0f
MyTextField.TextColor = RgbColor.Brown
MyTextField.DefaultValue = "ceTe Software"
MyTextField.MultiLine = true
MyTextField.ToolTip = "Text" 

Refer to the TextField API documentation for a complete example.

Signature Form Field

The Signature is a child class to the FormElement class. This example shows how to create a Signature and add it to the page.

Signature signature = new Signature("MySigField", 10, 10, 300, 100);
OpenTypeFont font  = new OpenTypeFont("fontname");
signature.Font = font;
signature.FullPanel.SetImage(@"C:\MyImage.gif");
signature.LeftPanel.TextColor = RgbColor.Red;        
Dim MySignature As Signature = New Signature("MySigField", 10, 10, 300, 100)
Dim MyFont As OpenTypeFont = New OpenTypeFont("fontname")
MySignature.Font = MyFont
MySignature.FullPanel.SetImage("C:\MyImage.gif")

MySignature.LeftPanel.TextColor = RgbColor.Red

Refer to the Signature API documentation for a complete example.

In this topic