Filling PDF form fields
Use PDF form filling to set field values from your application data.
Common use cases include:
- Prepopulating onboarding or registration forms
- Filling claim and compliance forms from backend systems
- Running batch form generation from CSV or database records
- Building template-based document assembly pipelines
In this guide, you’ll fill:
- Text fields
- Checkboxes
- Radio button groups
- Combo boxes
- List boxes
How Nutrient helps
Nutrient .NET SDK handles form field access, type-specific operations, and value validation.
The SDK handles:
- PDF form field dictionaries and field type detection
- Low-level value and method validation
- Hierarchy traversal for nested fields
- State synchronization for selection controls
Complete implementation
This example fills multiple form field types in one workflow.
using Nutrient;Opening a document with form fields
Open the document with a using statement(opens in a new tab), create an editor with PdfEditor.Edit(document), and get all form fields via editor.FormFieldCollection. Use the collection for lookup by fully qualified name. Inspect actual field names first (for example, print FullName for the fields you look up) before applying targeted updates:
try{ using Document document = Document.Open("input_forms.pdf"); using PdfEditor editor = PdfEditor.Edit(document); var formFields = editor.FormFieldCollection;Filling a text field
Find a text field by full name, verify that it exists and has the expected type, and assign the value with the Value property. FindByFullName() returns the concrete field subtype, such as PdfTextField or PdfCheckBoxField, or null when no field has that name. The inherited Value property writes the value for every field type — selection controls take the export value of the choice:
var textField = formFields.FindByFullName("Text1"); if (textField != null && textField.FieldType == PdfFormFieldType.Text) { textField.Value = "John Doe"; }Checking a checkbox
Find a checkbox field, verify the type, and assign its on-state export value. Checkbox export values are often "On" or "Yes" — the sample form uses "Yes":
var checkbox = formFields.FindByFullName("Check1"); if (checkbox != null && checkbox.FieldType == PdfFormFieldType.CheckBox) { checkbox.Value = "Yes"; }Selecting a radio button option
Find a radio group, verify the type, and assign one of its option export values:
var radioGroup = formFields.FindByFullName("RadioGroup1"); if (radioGroup != null && radioGroup.FieldType == PdfFormFieldType.RadioButton) { radioGroup.Value = "Option2"; }Selecting an item in a combo box
Find a combo box field, verify the type, and assign the export value of the choice you want.
Values must match a valid export value exactly:
var comboBox = formFields.FindByFullName("Dropdown1"); if (comboBox != null && comboBox.FieldType == PdfFormFieldType.ComboBox) { comboBox.Value = "Germany"; }Selecting an item in a list box
Find a list box field, verify the type, and assign the export value of the choice you want. The generic Value property selects a single value; multi-select isn’t yet supported in the .NET SDK:
var listBox = formFields.FindByFullName("List1"); if (listBox != null && listBox.FieldType == PdfFormFieldType.ListBox) { listBox.Value = "Technology"; }Filling several fields in one pass
Apply type-based updates to a list of known field names. Process only terminal, non-read-only fields:
foreach (var fullName in new[] { "Text1", "Check1" }) { var field = formFields.FindByFullName(fullName); if (field != null && field.IsTerminal && !field.IsReadOnly) { var fieldType = field.FieldType;
if (fieldType == PdfFormFieldType.Text) { field.Value = "Sample Value"; } else if (fieldType == PdfFormFieldType.CheckBox) { field.Value = "Yes"; } } }Saving the filled form
Save the output PDF.
In this sample:
SaveAs("output.pdf")writes a new file.- The
usingstatements release the editor and document handles. NutrientExceptionhandles runtime failures.
editor.SaveAs("output.pdf"); Console.WriteLine("Successfully filled form fields");}catch (NutrientException e){ Console.Error.WriteLine($"Error: {e.Message}"); Environment.Exit(1);}Conclusion
Use this workflow to fill PDF form fields:
- Open the document, create a PDF editor, and retrieve the form field collection with the
FormFieldCollectionproperty. - Use
FindByFullName()to locate specific fields by their fully qualified names (including hierarchy). - Verify field types with the
FieldTypeproperty before performing field-specific operations. - Fill text fields by setting
Valueto"...". - Fill checkbox, radio, combo, and list controls by setting
Valueto the control’s export values. - For checkbox and radio controls, use valid export values (for example, checkbox values are often
"On"or"Yes"). - For combo/list controls, values must match available option text/export values exactly.
- Batch-fill by walking a list of field names with conditional logic using
IsTerminalandFieldType. - Save the document with
SaveAs()to persist all filled field values. - Handle exceptions with try-catch blocks for robust error recovery in production workflows.
- The
usingstatements release the editor and document handles.
Field names used in this sample (
Text1,Check1,RadioGroup1,Dropdown1,List1) match the sample input form. Inspect actual field names in your PDF first and update lookups accordingly — method calls on a field looked up by a name that doesn’t exist throw aNutrientException.
For related form workflows, refer to the .NET SDK editor guides.