PdfForm Class
Represents interactive form of the PDF document.
Inherited Members
Namespace: Syncfusion.Pdf.Interactive
Assembly: Syncfusion.Pdf.Base.dll
Syntax
public class PdfForm : IPdfWrapper
Remarks
Please refer the UG docuemntation link https://help.syncfusion.com/file-formats/pdf/working-with-forms for more details of working with forms.
Examples
//Create a new PDf document
PdfDocument document = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
// Creates a form
PdfForm form = document.Form;
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create list box
PdfListBoxField listBox = new PdfListBoxField(page, "list1");
//Add the field to listbox.
form.Fields.Add(listBox);
//Set the properties.
listBox.Bounds = new RectangleF(100, 350, 100, 50);
listBox.HighlightMode = PdfHighlightMode.Outline;
//Add the items to the list box
listBox.Items.Add(new PdfListFieldItem("English", "English"));
listBox.Items.Add(new PdfListFieldItem("French", "French"));
listBox.Items.Add(new PdfListFieldItem("German", "German"));
//Select the item
listBox.SelectedIndex = 2;
//Set the multi-select option
listBox.MultiSelect = true;
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = document.Pages.Add()
' Creates a form
Dim form As PdfForm = document.Form
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create list box
Dim listBox As PdfListBoxField = New PdfListBoxField(page, "list1")
'Add the field to listbox.
form.Fields.Add(listBox)
'Set the properties.
listBox.Bounds = New RectangleF(100, 350, 100, 50)
listBox.HighlightMode = PdfHighlightMode.Outline
'Add the items to the list box
listBox.Items.Add(New PdfListFieldItem("English", "English"))
listBox.Items.Add(New PdfListFieldItem("French", "French"))
listBox.Items.Add(New PdfListFieldItem("German", "German"))
'Select the item
listBox.SelectedIndex = 2
'Set the multi-select option
listBox.MultiSelect = True
document.Save("Form.pdf")
document.Close(True)
Constructors
PdfForm()
Initializes a new instance of the PdfForm class.
Declaration
public PdfForm()
Examples
//Create a new PDf document
PdfDocument document = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
// Creates a form
PdfForm form = new PdfForm();
form = document.Form;
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create list box
PdfListBoxField listBox = new PdfListBoxField(page, "list1");
//Add the field to listbox.
form.Fields.Add(listBox);
//Set the properties.
listBox.Bounds = new RectangleF(100, 350, 100, 50);
listBox.HighlightMode = PdfHighlightMode.Outline;
//Add the items to the list box
listBox.Items.Add(new PdfListFieldItem("English", "English"));
listBox.Items.Add(new PdfListFieldItem("French", "French"));
listBox.Items.Add(new PdfListFieldItem("German", "German"));
//Select the item
listBox.SelectedIndex = 2;
//Set the multi-select option
listBox.MultiSelect = true;
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = document.Pages.Add()
' Creates a form
Dim form As PdfForm = New PdfForm()
form = document.Form
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create list box
Dim listBox As PdfListBoxField = New PdfListBoxField(page, "list1")
'Add the field to listbox.
form.Fields.Add(listBox)
'Set the properties.
listBox.Bounds = New RectangleF(100, 350, 100, 50)
listBox.HighlightMode = PdfHighlightMode.Outline
'Add the items to the list box
listBox.Items.Add(New PdfListFieldItem("English", "English"))
listBox.Items.Add(New PdfListFieldItem("French", "French"))
listBox.Items.Add(New PdfListFieldItem("German", "German"))
'Select the item
listBox.SelectedIndex = 2
'Set the multi-select option
listBox.MultiSelect = True
document.Save("Form.pdf")
document.Close(True)
See Also
Properties
ComplexScript
Gets or sets the complex script layout for form fields.
Declaration
public bool ComplexScript { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a new PDF page.
PdfPage page = document.Pages.Add();
//Create font.
Font font = new Font("Tahoma", 10f);
//Create a new PDF font instance.
PdfFont pdfFont = new PdfTrueTypeFont(font, FontStyle.Regular, 10f, true, true);
//Create a new text box field.
PdfTextBoxField textBox = new PdfTextBoxField(page, "textBox");
//Set bounds
textBox.Bounds = new RectangleF(0, 0, 300, 20);
//Set font.
textBox.Font = pdfFont;
//Set text.
textBox.Text = "สวัสดีชาวโลก";
//Add field to form.
document.Form.Fields.Add(textBox);
//Enable complex script
document.Form.ComplexScript = true;
document.Form.SetDefaultAppearance(false)
//Save the document.
document.Save("output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a new PDF page.
Dim page As PdfPage = document.Pages.Add()
'Create font.
Dim font As New Font("Tahoma", 10F)
'Create a new PDF font instance.
Dim pdfFont As PdfFont = New PdfTrueTypeFont(font, FontStyle.Regular, 10F, True, True)
'Create a new text box field.
Dim textBox As New PdfTextBoxField(page, "textBox")
'Set bounds
textBox.Bounds = New RectangleF(0, 0, 300, 20)
'Set font.
textBox.Font = pdfFont
'Set text.
textBox.Text = "สวัสดีชาวโลก"
'Add field to form.
document.Form.Fields.Add(textBox)
'Enable complex script
document.Form.ComplexScript = True
document.Form.SetDefaultAppearance(False)
'Save the document.
document.Save("output.pdf")
'Close the document.
document.Close(True)
DisableAutoFormat
Gets or sets whether to disable auto formating.
Declaration
public bool DisableAutoFormat { get; set; }
Property Value
Type |
---|
System.Boolean |
FieldAutoNaming
Gets or sets a value indicating whether [field auto naming].
Declaration
public bool FieldAutoNaming { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Examples
//Create a new PDf document
PdfDocument document = new PdfDocument();
// Creates a form
PdfForm form = document.Form;
// Sets the form fields as auto naming.
form.FieldAutoNaming = true;
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create a combo box
PdfComboBoxField positionComboBox = new PdfComboBoxField(page, "positionComboBox");
positionComboBox.Editable = true;
positionComboBox.Bounds = new RectangleF(100, 115, 200, 20);
positionComboBox.Font = font;
positionComboBox.Editable = true;
//Add it to document
document.Form.Fields.Add(positionComboBox);
PdfFieldCollection fieldCollection = document.Form.Fields;
// Flatten the form collection
for (int i = 0; i != fieldCollection.Count; i++)
{
fieldCollection[i].Flatten = true;
}
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
' Creates a form
Dim form As PdfForm = document.Form
' Sets the form fields as auto naming.
form.FieldAutoNaming = True
'Create a page
Dim page As PdfPage = document.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create a combo box
Dim positionComboBox As PdfComboBoxField = New PdfComboBoxField(page, "positionComboBox")
positionComboBox.Editable = True
positionComboBox.Bounds = New RectangleF(100, 115, 200, 20)
positionComboBox.Font = font
positionComboBox.Editable = True
'Add it to document
document.Form.Fields.Add(positionComboBox)
Dim fieldCollection As PdfFieldCollection = document.Form.Fields
' Flatten the form collection
For i As Integer = 0 To fieldCollection.Count - 1
fieldCollection(i).Flatten = True
Next i
document.Save("Form.pdf")
document.Close(True)
See Also
Fields
Gets the fields collection.[Read-Only]
Declaration
public PdfFormFieldCollection Fields { get; }
Property Value
Type | Description |
---|---|
PdfFormFieldCollection | The Form fields. |
Examples
//Create a new PDf document
PdfDocument document = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create a combo box
PdfComboBoxField positionComboBox = new PdfComboBoxField(page, "positionComboBox");
positionComboBox.Editable = true;
positionComboBox.Bounds = new RectangleF(100, 115, 200, 20);
positionComboBox.Font = font;
positionComboBox.Editable = true;
//Add it to document
document.Form.Fields.Add(positionComboBox);
PdfFieldCollection fieldCollection = document.Form.Fields;
// Flatten the form collection
for (int i = 0; i != fieldCollection.Count; i++)
{
fieldCollection[i].Flatten = true;
}
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = document.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create a combo box
Dim positionComboBox As PdfComboBoxField = New PdfComboBoxField(page, "positionComboBox")
positionComboBox.Editable = True
positionComboBox.Bounds = New RectangleF(100, 115, 200, 20)
positionComboBox.Font = font
positionComboBox.Editable = True
'Add it to document
document.Form.Fields.Add(positionComboBox)
Dim fieldCollection As PdfFieldCollection = document.Form.Fields
'Flatten the form collection
For i As Integer = 0 To fieldCollection.Count - 1
fieldCollection(i).Flatten = True
Next i
document.Save("Form.pdf")
document.Close(True)
See Also
Flatten
PDF provides support to flatten a form field by removing the existing form field and replacing it with graphical objects that would resemble the form field and cannot be edited.
Gets or sets a value indicating whether this PdfForm is flatten.Declaration
public bool Flatten { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
//Create a new PDf document
PdfDocument document = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create a combo box
PdfComboBoxField positionComboBox = new PdfComboBoxField(page, "positionComboBox");
positionComboBox.Editable = true;
positionComboBox.Bounds = new RectangleF(100, 115, 200, 20);
positionComboBox.Font = font;
positionComboBox.Editable = true;
//Add it to document
document.Form.Fields.Add(positionComboBox);
PdfFieldCollection fieldCollection = document.Form.Fields;
// Flatten the form collection
for (int i = 0; i != fieldCollection.Count; i++)
{
fieldCollection[i].Flatten = true;
}
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = document.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create a combo box
Dim positionComboBox As PdfComboBoxField = New PdfComboBoxField(page, "positionComboBox")
positionComboBox.Editable = True
positionComboBox.Bounds = New RectangleF(100, 115, 200, 20)
positionComboBox.Font = font
positionComboBox.Editable = True
'Add it to document
document.Form.Fields.Add(positionComboBox)
Dim fieldCollection As PdfFieldCollection = document.Form.Fields
' Flatten the form collection
For i As Integer = 0 To fieldCollection.Count - 1
fieldCollection(i).Flatten = True
Next i
document.Save("Form.pdf")
document.Close(True)
See Also
IsDefaultEncoding
Gets or sets whether the form is default encoding or not.
Declaration
public bool IsDefaultEncoding { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
//Create a new PDf document
PdfDocument document = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create a combo box
PdfComboBoxField positionComboBox = new PdfComboBoxField(page, "positionComboBox");
positionComboBox.Editable = true;
positionComboBox.Bounds = new RectangleF(100, 115, 200, 20);
positionComboBox.Font = font;
positionComboBox.Editable = true;
//Add it to document
document.Form.Fields.Add(positionComboBox);
PdfFieldCollection fieldCollection = document.Form.Fields;
// Flatten the form collection
for (int i = 0; i != fieldCollection.Count; i++)
{
fieldCollection[i].Flatten = true;
}
Set default encoding to form.
form.IsDefaultEncoding = true;
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = document.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create a combo box
Dim positionComboBox As PdfComboBoxField = New PdfComboBoxField(page, "positionComboBox")
positionComboBox.Editable = True
positionComboBox.Bounds = New RectangleF(100, 115, 200, 20)
positionComboBox.Font = font
positionComboBox.Editable = True
'Add it to document
document.Form.Fields.Add(positionComboBox)
Dim fieldCollection As PdfFieldCollection = document.Form.Fields
'Flatten the form collection
For i As Integer = 0 To fieldCollection.Count - 1
fieldCollection(i).Flatten = True
Next i
Set default encoding to form.
form.IsDefaultEncoding = True
document.Save("Form.pdf")
document.Close(True)
See Also
ReadOnly
Gets or sets a value indicating whether the form is read only.
Declaration
public virtual bool ReadOnly { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Examples
//Create a new PDf document
PdfDocument document = new PdfDocument();
PdfForm form = document.Form;
// Sets the form as read only
form.ReadOnly = true;
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create a combo box
PdfComboBoxField positionComboBox = new PdfComboBoxField(page, "positionComboBox");
positionComboBox.Editable = true;
positionComboBox.Bounds = new RectangleF(100, 115, 200, 20);
positionComboBox.Font = font;
positionComboBox.Editable = true;
//Add it to document
document.Form.Fields.Add(positionComboBox);
PdfFieldCollection fieldCollection = document.Form.Fields;
// Flatten the form collection
for (int i = 0; i != fieldCollection.Count; i++)
{
fieldCollection[i].Flatten = true;
}
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
' Creates a form
Dim form As PdfForm = document.Form
' Sets the form as read only
form.ReadOnly = True
'Create a page
Dim page As PdfPage = document.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create a combo box
Dim positionComboBox As PdfComboBoxField = New PdfComboBoxField(page, "positionComboBox")
positionComboBox.Editable = True
positionComboBox.Bounds = New RectangleF(100, 115, 200, 20)
positionComboBox.Font = font
positionComboBox.Editable = True
'Add it to document
document.Form.Fields.Add(positionComboBox)
Dim fieldCollection As PdfFieldCollection = document.Form.Fields
' Flatten the form collection
For i As Integer = 0 To fieldCollection.Count - 1
fieldCollection(i).Flatten = True
Next i
document.Save("Form.pdf")
document.Close(True)
See Also
Methods
SetDefaultAppearance(Boolean)
Specifies whether to set the default appearance for the form or not.
Declaration
public void SetDefaultAppearance(bool applyDefault)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | applyDefault |
Examples
//Create a new PDf document
PdfDocument document = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
// Creates a form
PdfForm form = document.Form;
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f);
//Create list box
PdfListBoxField listBox = new PdfListBoxField(page, "list1");
//Add the field to listbox.
form.Fields.Add(listBox);
//Set the properties.
listBox.Bounds = new RectangleF(100, 350, 100, 50);
listBox.HighlightMode = PdfHighlightMode.Outline;
//Add the items to the list box
listBox.Items.Add(new PdfListFieldItem("English", "English"));
listBox.Items.Add(new PdfListFieldItem("French", "French"));
listBox.Items.Add(new PdfListFieldItem("German", "German"));
//Select the item
listBox.SelectedIndex = 2;
//Set the multi-select option
listBox.MultiSelect = true;
//Enable the default Appearance
form.SetDefaultAppearance(true);
document.Save("Form.pdf");
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = document.Pages.Add()
' Creates a form
Dim form As PdfForm = document.Form
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create list box
Dim listBox As PdfListBoxField = New PdfListBoxField(page, "list1")
'Add the field to listbox.
form.Fields.Add(listBox)
'Set the properties.
listBox.Bounds = New RectangleF(100, 350, 100, 50)
listBox.HighlightMode = PdfHighlightMode.Outline
'Add the items to the list box
listBox.Items.Add(New PdfListFieldItem("English", "English"))
listBox.Items.Add(New PdfListFieldItem("French", "French"))
listBox.Items.Add(New PdfListFieldItem("German", "German"))
'Select the item
listBox.SelectedIndex = 2
'Set the multi-select option
listBox.MultiSelect = True
'Enable the default Appearance
form.SetDefaultAppearance(True)
document.Save("Form.pdf")
document.Close(True)