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:
Step-by-step Guide:
Полный код
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 });
}
}
}
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
Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу support@sautinsoft.ru или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже: