The Interaction Form in PDF using C# and .NET

Interactive forms in PDF, also known as AcroForms, allow users to enter data directly into the document. This is particularly useful for creating surveys, questionnaires, and other documents that require user input. In this article, we will explore how to fill in interactive PDF forms using C# and .NET with the help of the SautinSoft PDF.Net library.

Filling out forms it is designed to automate the process of entering data into interactive PDF documents. This is especially useful in the following cases:

  • Automation of business processes: Filling out forms can be automated to speed up the processing of documents such as questionnaires, surveys, applications and contracts.
  • Data Collection: It is easy to collect and process data from users, which simplifies the analysis and storage of information.
  • Improved user experience: Users can fill out forms electronically, which is more convenient and faster than manually filling out paper forms.
  • Error reduction: Automatic form filling reduces the likelihood of errors related to manual data entry.
  • Integration with other systems: Completed forms can be easily integrated with other systems and databases for further processing and analysis.
  • Data unification: Ensures uniformity and standardization of data, which is important for reporting and analysis.

Step-by-step Guide:

  1. Add SautinSoft.PDF from NuGet.
  2. Load the PDF document with forms.
  3. Read the form fields.
  4. Fill the form fields.
  5. Save the document.

Output result:

Complete code

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

namespace Sample
{
    class Sample
    {
        /// <summary>
        /// Fill in PDF interactive forms.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/fill-in-pdf-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(@"..\..\..\Form.pdf");

            //Load PDF Document with forms.
            using (var document = PdfDocument.Load(pdfFile))
            {
                // Fill the form fields.
                document.Form.Fields["FullName"].Value = "Jane Doe";
                document.Form.Fields["ID"].Value = "0123456789";
                document.Form.Fields["Gender"].Value = "Female";
                document.Form.Fields["Married"].Value = "Yes";
                document.Form.Fields["City"].Value = "Berlin";
                document.Form.Fields["Language"].Value = new string[] { "German", "Italian" };
                document.Form.Fields["Notes"].Value = "Notes first line\rNotes second line\rNotes third line";

                // Save PDF Document.
                document.Save("FormFilled.pdf");
            }

            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("FormFilled.pdf") { UseShellExecute = true });
        }
    }
}

Download

Option Infer On

Imports Microsoft.VisualBasic
Imports System
Imports System.IO
Imports SautinSoft
Imports SautinSoft.Pdf
Imports SautinSoft.Pdf.Content

Namespace Sample
	Friend Class Sample
		''' <summary>
		''' Fill in PDF interactive forms.
		''' </summary>
		''' <remarks>
		''' Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/fill-in-pdf-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("..\..\..\Form.pdf")

			'Load PDF Document with forms.
			Using document = PdfDocument.Load(pdfFile)
				' Fill the form fields.
				document.Form.Fields("FullName").Value = "Jane Doe"
				document.Form.Fields("ID").Value = "0123456789"
				document.Form.Fields("Gender").Value = "Female"
				document.Form.Fields("Married").Value = "Yes"
				document.Form.Fields("City").Value = "Berlin"
				document.Form.Fields("Language").Value = New String() { "German", "Italian" }
				document.Form.Fields("Notes").Value = "Notes first line" & vbCr & "Notes second line" & vbCr & "Notes third line"

				' Save PDF Document.
				document.Save("FormFilled.pdf")
			End Using

			System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo("FormFilled.pdf") With {.UseShellExecute = True})
		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.