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.

Полный код

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


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу support@sautinsoft.ru или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.