Fill in PDF interactive form in C# and VB.NET
GemBox.Pdf supports filling in a PDF interactive form.
Currently, only filling in of toggle button fields (PdfCheckBoxField
and PdfRadioButtonField
) is supported.
The following example shows how you can fill in check box and radio button fields in a PDF interactive form.

using System.Linq;
using GemBox.Pdf;
using GemBox.Pdf.Forms;
class Program
{
static void Main()
{
// If using Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
using (var document = PdfDocument.Load("%InputFileName%"))
{
// Set check box field checked state.
var marriedCheckBox = (PdfCheckBoxField)document.Form.Fields["Married"];
marriedCheckBox.Checked = true;
// Set check box field value.
var drivingLicenseCheckBox = (PdfCheckBoxField)document.Form.Fields["Driving License"];
drivingLicenseCheckBox.Value = "Yes";
// Set radio button field checked state.
// There are multiple radio button fields with name 'Gender' so
// set checked state only to the radio button field whose choice is 'Male'.
foreach (PdfRadioButtonField genderRadioButton in document.Form.Fields.Where(field => field.Name == "Gender"))
genderRadioButton.Checked = genderRadioButton.Choice == "Male";
// Set radio button field value.
// It is enough to set value to only one radio button field
// from a group of radio button fields with name 'Age'.
var ageRadioButton = (PdfRadioButtonField)document.Form.Fields["Age"];
ageRadioButton.Value = "18 - 39";
document.Save("Fill in Form.pdf");
}
}
}
Imports System.Linq
Imports GemBox.Pdf
Imports GemBox.Pdf.Forms
Module Program
Sub Main()
' If using Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY")
Using document = PdfDocument.Load("%InputFileName%")
' Set check box field checked state.
Dim marriedCheckBox = CType(document.Form.Fields("Married"), PdfCheckBoxField)
marriedCheckBox.Checked = True
' Set check box field value.
Dim drivingLicenseCheckBox = CType(document.Form.Fields("Driving License"), PdfCheckBoxField)
drivingLicenseCheckBox.Value = "Yes"
' Set radio button field checked state.
' There are multiple radio button fields with name 'Gender' so
' set checked state only to the radio button field whose choice is 'Male'.
For Each genderRadioButton As PdfRadioButtonField In document.Form.Fields.Where(Function(field) field.Name = "Gender")
genderRadioButton.Checked = genderRadioButton.Choice = "Male"
Next
' Set radio button field value.
' It is enough to set value to only one radio button field
' from a group of radio button fields with name 'Age'.
Dim ageRadioButton = CType(document.Form.Fields("Age"), PdfRadioButtonField)
ageRadioButton.Value = "18 - 39"
document.Save("Fill in Form.pdf")
End Using
End Sub
End Module
Want more?
Like it?
Published: February 19, 2019 | Modified: September 3, 2020 | Author: Stipo Rubić