How to Start Tutorials Troubleshooting Main Operations Convert PDF Read PDF Edit PDF PDF Report Generator Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

C# PDF Form Process Library
How to open, read, parse, view PDF file form field data using c# in winform, asp.net


Help to Read and Extract Field Data from PDF with a Convenient C# Solution in .NET Application





In this tutorial, you will learn how to read, extract PDF AcroForm fields data using C# in your .NET web and Windows applications.

  • Read AcroForm field data
  • Retrieve all form fields from a PDF file
  • Search, find a field by page postion, by field name
  • Support all AcroForms fields, including check box, radio button, text box, list box, combo box
  • Extract field properties: name, visibility, page index, position, and size

How to read, extract PDF AcroForm fields data programmatically using C#

  1. Download XDoc.PDF AcroForm C# library
  2. Install C# library to read, extract AcroForm field data programmatically
  3. Step by Step Tutorial








  • A best PDF document SDK library enable users abilities to read and extract PDF form data in Visual C#.NET WinForm and ASP.NET WebForm applications
  • Provide advanced .NET framework components for extracting data from PDF file use Visual Studio .NET-compliant C# language
  • Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
  • A professional PDF form reader control able to read PDF form field in C#.NET class
  • C# class source codes for collect data from PDF forms in Visual C# .NET program
  • Able to retrieve all form fields from adobe PDF file in C#.NET
  • Support to get form data from specified PDF form position
  • Special customization for export PDF form data to Excel spreadsheet in C#.NET


Generally, for a full-featured PDF software, it should have functions for processing text, image as well as field. RasterEdge .NET PDF SDK is such one provide various of form field edit functions. This page is mainly designed to tell you how to read or retrieve field data from PDF and how to extract and get field data from PDF in C#.NET project. C# demo codes listed below can help you have a quick evaluation of our PDF SDK.







Read, extract PDF forms data using c#


To get data values from all form fields in a PDF document, you need navigate through all form fields and read, extract data value.

  1. Use PDFFormHandler.GetFormFields() to get all form fields data in list of BaseFormField objects from an existing PDF file
  2. For each form field in object BaseFormField, you can get the field type, its value



String inputFilePath = Program.RootPath + "\\" + "1_AF_Filled.pdf";

List<BaseFormField> fields = PDFFormHandler.GetFormFields(inputFilePath);
Console.WriteLine("Number of Fields: " + fields.Count);
if (fields.Count > 0)
{
    foreach (BaseFormField field in fields)
    {
        Console.WriteLine("Field");
        Console.WriteLine("  Name:      " + field.Name);

        if (field is AFCheckBox)
        {
            Console.WriteLine("  Type:      " + "CheckBox");
            Console.WriteLine("  IsChecked: " + ((AFCheckBox)field).IsChecked);
        }
        else if (field is AFRadioButton)
        {
            Console.WriteLine("  Type:      " + "RadioButton");
            Console.WriteLine("  IsChecked: " + ((AFRadioButton)field).IsChecked);
        }
        else if (field is AFTextBox)
        {
            Console.WriteLine("  Type:      " + "TextBox");
            Console.WriteLine("  Content:   " + ((AFTextBox)field).Text);
        }
        else if (field is AFListBox)
        {
            Console.WriteLine("  Type:                " + "ListBox");
            Console.WriteLine("  Selected Item Index: " + ((AFListBox)field).SelectedIndexes[0]);
        }
        else if (field is AFComboBox)
        {
            Console.WriteLine("  Type:                " + "ComboBox");
            Console.WriteLine("  Selected Item Index: " + ((AFComboBox)field).SelectedIndex);
        }
    }
}




Retrieve and parse all form fields from a PDF file using c#


To get field properties from all form fields in a PDF document, you need navigate through all form fields in C# code.

  1. Use PDFFormHandler.GetFormFields() to get all form fields data in list of BaseFormField objects from an existing PDF file
  2. For each form field in object BaseFormField, you could read field properties, including field name, visible or not, page index, page position, and size

String inputFilePath = Program.RootPath + "\\" + "1_AF.pdf";

List<BaseFormField> fields = PDFFormHandler.GetFormFields(inputFilePath);
Console.WriteLine("Number of Fields: " + fields.Count);
if (fields.Count > 0)
{
    foreach (BaseFormField field in fields)
    {
        Console.WriteLine("Field");
        Console.WriteLine("  Name:     " + field.Name);
        Console.WriteLine("  Visible:  " + field.IsVisible);
        Console.WriteLine("  Page:     " + field.PageIndex);
        Console.WriteLine("  Position: " + field.Position.ToString());
        Console.WriteLine("  Size: " + field.Size.ToString());
    }
}




Select, parse a PDF form field in a page by position using c#


The text and C# source code below will show how to get field by page position from a PDF file using C#

  1. Define a page postion, new PointF(110, 310)
  2. Use PDFFormHandler.GetFormField() to get a form field by the position of the first page of pdf document



String inputFilePath = Program.RootPath + "\\" + "1_AF.pdf";

//  select a field at position [110, 310] in page 1 (page index 0)
int pageIndex = 0;
PointF pos = new PointF(110, 310);
//  get the form field object
BaseFormField field = PDFFormHandler.GetFormField(inputFilePath, pageIndex, pos);
if (field != null)
{
    Console.WriteLine("Field " + field.Name + " in page " + field.PageIndex + " at " + field.Position.ToString());
}
else
{
    Console.WriteLine("Field " + field.Name + " does not exist");
}




Select, parse a form field in a PDF document by the name using c#


Here we will introduce how to select and parse PDF form field by field name in C# code

  1. Get a form field name, for example "AF_RadioButton_01"
  2. Utilize PDFFormHandler.SelectFormField() to find, and parse a form field by the field name in an existing PDF file



String inputFilePath = Program.RootPath + "\\" + "1_AF.pdf";

//  select a field with name "AF_RadioButton_01"
String fieldName = @"AF_RadioButton_01";
//  get the form field object
BaseFormField field = PDFFormHandler.SelectFormField(inputFilePath, fieldName);
if (field != null)
{
    Console.WriteLine("Field " + field.Name + " in page " + field.PageIndex + " at " + field.Position.ToString());
}
else
{
    Console.WriteLine("Field " + field.Name + " does not exist");
}