Table of Contents

Class PdfFieldCollection

Namespace
Syncfusion.Pdf.Interactive
Assembly
Syncfusion.Pdf.Portable.dll

Represents the collection of the PDF fields.

public class PdfFieldCollection : PdfCollection, IEnumerable
Inheritance
PdfFieldCollection
Implements
Derived
Inherited Members

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.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;
}
//Save the document to disk.
document.Save("Form.pdf");
//Close the document.
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.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
'Save the document to disk.
document.Save("Form.pdf")
'Close the document.
document.Close(True)

Remarks

This PdfFormFieldCollection class is used to get the collection of form fields. Please refer the UG docuemntation link for more details.

Constructors

PdfFieldCollection()

Initializes a new instance of the PdfFieldCollection class.

public PdfFieldCollection()

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.Bounds = new RectangleF(100, 115, 200, 20);
positionComboBox.Font = font;
positionComboBox.Editable = true;
//Add it to document
document.Form.Fields.Add(positionComboBox);
PdfFieldCollection fieldCollection = new PdfFieldCollection();
fieldCollection = document.Form.Fields;
// Flatten the form collection
for (int i = 0; i != fieldCollection.Count; i++)
{
 fieldCollection[i].Flatten = true;
}
//Save the document to disk.
document.Save("Form.pdf");
//Close the document.
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.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 = New PdfFieldCollection()
fieldCollection = document.Form.Fields
' Flatten the form collection
For i As Integer = 0 To fieldCollection.Count - 1
fieldCollection(i).Flatten = True
Next i
'Save the document to disk.
document.Save("Form.pdf")
'Close the document.
document.Close(True)
See Also

Properties

this[int]

Gets the PdfField at the specified index.[Read-Only]

public virtual PdfField this[int index] { get; }

Parameters

index int

Property Value

PdfField

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.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;
}
//Save the document to disk.
document.Save("Form.pdf");
//Close the document.
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
'Save the document to disk.
document.Save("Form.pdf")
'Close the document.
document.Close(True)
See Also

this[string]

Gets the PdfField with their field name.[Read-Only]

public PdfField this[string name] { get; }

Parameters

name string

Property Value

PdfField

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.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
fieldCollection["positionComboBox"].Flatten = true;
//Save the document to disk.
document.Save("Form.pdf");
//Close the document.
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
fieldCollection("positionComboBox").Flatten = True
'Save the document to disk.
document.Save("Form.pdf")
'Close the document.
document.Close(True)
See Also

Methods

Add(PdfField)

Adds the specified field to the collection.

public int Add(PdfField field)

Parameters

field PdfField

The field item which is added in the PDF form.

Returns

int

The field to be added on the page.

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);                     
PdfFieldCollection fieldCollection = document.Form.Fields;
//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;
fieldCollection.Add(positionComboBox as PdfField);
//Save the document to disk.
document.Save("Form.pdf");
//Close the document.
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)
Dim fieldCollection As PdfFieldCollection = document.Form.Fields
'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
fieldCollection.Add(TryCast(positionComboBox, PdfField))
'Save the document to disk.
document.Save("Form.pdf")
'Close the document.
document.Close(True)
See Also

Clear()

Clears the form field collection.

public void Clear()

Examples

//Load the PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Form.pdf");
//Get the field collections.
PdfFieldCollection fieldCollection = loadedDocument.Form.Fields;
//Clears the form field collection.
fieldCollection.Clear();
//Save the document to disk.
loadedDocument.Save("Sample.pdf");
//Close the document.
loadedDocument.Close(true);
'Load the PDF document.
Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf")
'Get the field collections.
Dim fieldCollection As PdfFieldCollection = loadedDocument.Form.Fields
'Clears the form field collection.
fieldCollection.Clear();
'Save the document to disk.
loadedDocument.Save("Sample.pdf")
'Close the document.
loadedDocument.Close(true)
See Also

Contains(PdfField)

Determines whether field is contained within the collection.

public bool Contains(PdfField field)

Parameters

field PdfField

Check whether PdfField object is present in the field collection or not.

Returns

bool

true if field is present in the collection, otherwise, false.

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);                     
PdfFieldCollection fieldCollection = document.Form.Fields;
//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;
if (fieldCollection.Contains(positionComboBox as PdfField))
 MessageBox.Show("Already added field");
else
 fieldCollection.Add(positionComboBox as PdfField);
 //Save the document to disk.
document.Save("Form.pdf");
//Close the document.
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)
Dim fieldCollection As PdfFieldCollection = document.Form.Fields
'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
If fieldCollection.Contains(TryCast(positionComboBox, PdfField)) Then
MessageBox.Show("Already added field")
Else
fieldCollection.Add(TryCast(positionComboBox, PdfField))
End If
'Save the document to disk.
document.Save("Form.pdf")
'Close the document.
document.Close(True)
See Also

DoAdd(PdfField)

Adds a field to collection.

protected virtual int DoAdd(PdfField field)

Parameters

field PdfField

The field.

Returns

int

field.

See Also

DoAdd(PdfXfaForm, string)

Add the specified XFA form fields

protected virtual void DoAdd(PdfXfaForm form, string subformName)

Parameters

form PdfXfaForm
subformName string
See Also

DoClear()

Clears the collection.

protected virtual void DoClear()
See Also

DoInsert(int, PdfField)

Inserts a filed into collection.

protected virtual void DoInsert(int index, PdfField field)

Parameters

index int

The index.

field PdfField

The field.

See Also

DoRemove(PdfField)

Removes the field from collection.

protected virtual void DoRemove(PdfField field)

Parameters

field PdfField

The field.

See Also

DoRemoveAt(int)

Removes the field at the specified position.

protected virtual void DoRemoveAt(int index)

Parameters

index int

The index.

See Also

IndexOf(PdfField)

Gets the index of the specific field.

public int IndexOf(PdfField field)

Parameters

field PdfField

The PdfField object whose index is requested.

Returns

int

Index of the field in collection.

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);
PdfFieldCollection fieldCollection = document.Form.Fields;
//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;
document.Form.Fields.Add(positionComboBox);
int index = fieldCollection.IndexOf(positionComboBox as PdfField);
//Save the document to disk.
document.Save("Form.pdf");
//Close the document.
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)
Dim fieldCollection As PdfFieldCollection = document.Form.Fields
'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
document.Form.Fields.Add(positionComboBox)
Dim index As Integer = fieldCollection.IndexOf(TryCast(positionComboBox, PdfField))
'Save the document to disk.
document.Save("Form.pdf")
'Close the document.
document.Close(True)
See Also

Insert(int, PdfField)

Inserts the field at the specified index.

public void Insert(int index, PdfField field)

Parameters

index int

The index of the field.

field PdfField

The field which should be inserted at the specified index.

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 check box
PdfCheckBoxField checkBox = new PdfCheckBoxField(page, "C#.NET");
checkBox.Bounds = new RectangleF(100, 290, 20, 20);
document.Form.Fields.Add(checkBox);
checkBox.HighlightMode = PdfHighlightMode.Push;
checkBox.BorderStyle = PdfBorderStyle.Beveled;
//Set the value for the check box
checkBox.Checked = true;
document.Form.Fields.Add(checkBox);
PdfFieldCollection fieldCollection = document.Form.Fields;
//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;
// Insert the field at first position in the collection
fieldCollection.Insert(0, positionComboBox as PdfField);
//Save the document to disk.
document.Save("Form.pdf");
//Close the document.
document.Close(true);
'Create a new PDf document
Dim document As PdfDocument = New PdfDocument()
'Creates a new page and adds it as the last page of the document
Dim page As PdfPage = document.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12f)
'Create a check box
Dim checkBox As PdfCheckBoxField = New PdfCheckBoxField(page, "C#.NET")
checkBox.Bounds = New RectangleF(100, 290, 20, 20)
document.Form.Fields.Add(checkBox)
checkBox.HighlightMode = PdfHighlightMode.Push
checkBox.BorderStyle = PdfBorderStyle.Beveled
'Set the value for the check box
checkBox.Checked = True
document.Form.Fields.Add(checkBox)
Dim fieldCollection As PdfFieldCollection = document.Form.Fields
'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
' Insert the field at first position in the collection
fieldCollection.Insert(0, TryCast(positionComboBox, PdfField))
'Save the document to disk.
document.Save("Form.pdf")
'Close the document.
document.Close(True)
See Also

Remove(PdfField)

Removes the specified field in the collection.

public void Remove(PdfField field)

Parameters

field PdfField

The PdfField object to be removed from collection.

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);
PdfFieldCollection fieldCollection = document.Form.Fields;
//Create a combo box
PdfComboBoxField positionComboBox = new PdfComboBoxField(page, "positionComboBox");
document.Form.Fields.Add(positionComboBox);
positionComboBox.Editable = true;      
positionComboBox.Bounds = new RectangleF(100, 115, 200, 20);
positionComboBox.Font = font;
positionComboBox.Editable = true;          
fieldCollection.Remove(positionComboBox as PdfField);
//Save the document to disk.
document.Save("Form.pdf");
//Close the document.
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)
Dim fieldCollection As PdfFieldCollection = document.Form.Fields
'Create a combo box
Dim positionComboBox As PdfComboBoxField = New PdfComboBoxField(page, "positionComboBox")
document.Form.Fields.Add(positionComboBox)
positionComboBox.Editable = True
positionComboBox.Bounds = New RectangleF(100, 115, 200, 20)
positionComboBox.Font = font
positionComboBox.Editable = True
fieldCollection.Remove(TryCast(positionComboBox, PdfField))
'Save the document to disk.
document.Save("Form.pdf")
'Close the document.
document.Close(True)
See Also

RemoveAt(int)

Removes field at the specified position.

public void RemoveAt(int index)

Parameters

index int

The index where to remove the item.

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);
PdfFieldCollection fieldCollection = document.Form.Fields;
//Create a combo box
PdfComboBoxField positionComboBox = new PdfComboBoxField(page, "positionComboBox");
document.Form.Fields.Add(positionComboBox);
positionComboBox.Editable = true;
positionComboBox.Bounds = new RectangleF(100, 115, 200, 20);
positionComboBox.Font = font;
positionComboBox.Editable = true;
// Remove the first element
fieldCollection.RemoveAt(0);
//Save the document to disk.
document.Save("Form.pdf");
//Close the document.
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)
Dim fieldCollection As PdfFieldCollection = document.Form.Fields
'Create a combo box
Dim positionComboBox As PdfComboBoxField = New PdfComboBoxField(page, "positionComboBox")
document.Form.Fields.Add(positionComboBox)
positionComboBox.Editable = True
positionComboBox.Bounds = New RectangleF(100, 115, 200, 20)
positionComboBox.Font = font
positionComboBox.Editable = True
' Remove the first element
fieldCollection.RemoveAt(0)
'Save the document to disk.
document.Save("Form.pdf")
'Close the document.
document.Close(True)
See Also

See Also