Managing PDF Form Fields with C# and .NET

Exporting interactive form fields from a PDF document is a common requirement in many applications. This process can be efficiently handled using the SautinSoft PDF .Net library. Below, we will explore how to achieve this using C# and .NET. Extraction form fields from a PDF document to a PDF.Net can be useful in various scenarios. Here are a few key reasons why this might be necessary.

  • Automation of data processing. Exporting data from forms allows you to automate the process of collecting and processing information, which is especially useful for organizations that regularly collect data through PDF forms (for example, questionnaires, surveys, applications).
  • Integration with other systems. Exported data can be easily integrated with other systems and databases. For example, data from a PDF form can be exported to JSON or XML and then imported into a CRM system or database.
  • Analysis and reporting. Exporting data to structured formats (for example, CSV, JSON) makes it easy to analyze and create reports based on the collected information.
  • Archiving and Backup. Exporting data from forms allows you to create backups of completed forms in easy-to-store and search formats.
  • User-friendliness. Users can fill out forms offline and then submit them for processing. Exporting data makes it easy to extract and process this data.
  • Data unification. Exporting data to standard formats (e.g. FDF, XFDF) ensures data unification, which simplifies their further processing and analysis.

Complete code

using System;
using System.IO;
using SautinSoft;
using SautinSoft.Pdf;
using SautinSoft.Pdf.Content;

namespace Sample
{
    class Sample
    {
        /// <summary>
        /// Export form fields data to fdf/xfdf/json document.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/export-interactive-forms.php
        /// </remarks>
        static void Main(string[] args)
        {
            // Before starting this example, please get a free 100-day trial key:
            // https://sautinsoft.com/start-for-free/

            // Apply the key here:
            // PdfDocument.SetLicense("...");

            string pdfFile = Path.GetFullPath(@"..\..\..\FormFilled.pdf");

            using (var document = PdfDocument.Load(pdfFile))
            {
                //Export form data as fdf stream.
                var fdfFile = new FileStream("..\\..\\..\\fdfOut.fdf", FileMode.Create);
                document.Form.ExportData(fdfFile, SautinSoft.Pdf.Forms.PdfFormDataFormat.FDF);

                //Export form data to xfdf file.
                document.Form.ExportData("..\\..\\..\\xfdfOut.xfdf");

                //Export form data to json file.
                document.Form.ExportData("..\\..\\..\\jsonOut.json");
            }
        }
    }
}

Download

Option Infer On

Imports System
Imports System.IO
Imports SautinSoft
Imports SautinSoft.Pdf
Imports SautinSoft.Pdf.Content

Namespace Sample
	Friend Class Sample
		''' <summary>
		''' Export form fields data to fdf/xfdf/json document.
		''' </summary>
		''' <remarks>
		''' Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/export-interactive-forms.php
		''' </remarks>
		Shared Sub Main(ByVal args() As String)
			' Before starting this example, please get a free 100-day trial key:
			' https://sautinsoft.com/start-for-free/

			' Apply the key here:
			' PdfDocument.SetLicense("...");

			Dim pdfFile As String = Path.GetFullPath("..\..\..\FormFilled.pdf")

			Using document = PdfDocument.Load(pdfFile)
				'Export form data as fdf stream.
				Dim fdfFile = New FileStream("fdfOut.fdf", FileMode.Create)
				document.Form.ExportData(fdfFile, SautinSoft.Pdf.Forms.PdfFormDataFormat.FDF)

				'Export form data to xfdf file.
				document.Form.ExportData("xfdfOut.xfdf")

				'Export form data to json file.
				document.Form.ExportData("jsonOut.json")
			End Using
		End Sub
	End Class
End Namespace

Download


If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below:



Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.