Read PDF form fields in C# .NET

To read a form field’s data in a PDF document, use one of the methods starting with the GetFormField prefix. All these methods require the form field ID as their parameter. The list below contains the most commonly used methods:

The following example finds all text form fields in a document and prints their content to the console:

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Determine the number of form fields.
int fieldCount = gdpicturePDF.GetFormFieldsCount();
// Loop through all form fields.
for (int i = 0; i < fieldCount; i++)
{
// Get the field ID of each form field.
int fieldID = gdpicturePDF.GetFormFieldId(i);
// Check if the current field is a text box.
if (gdpicturePDF.GetFormFieldType(fieldID) == PdfFormFieldType.PdfFormFieldTypeText)
{
// Get the current form field's value and print it to the console.
string fieldValue = gdpicturePDF.GetFormFieldValue(fieldID);
Console.WriteLine(fieldValue);
}
}