Fill PDF form

This code sample shows how to assign values to various types of PDF form fields.

C#

using (var fileIn = new FileStream("form.pdf", FileMode.Open, FileAccess.Read))
{
   // open PDF
   Document document = new Document(fileIn);

   // set the value of text field
   TextField textField = document.Fields["Text1"] as TextField;
   textField.Value = "Hello";

   // check check box
   CheckBoxField checkBox = document.Fields["CheckBox2"] as CheckBoxField;
   checkBox.CheckBoxValue = CheckState.On;

   // select second radio button option
   // (range checking omitted for the purpose of this code sample)
   RadioButtonField radioButton = document.Fields["Radio Button4"] as RadioButtonField;
   radioButton.RadioButtonValue = radioButton.Options[0]; //select first option

   // select second item in list box
   ListBoxField listBox = document.Fields["ListBox7"] as ListBoxField;
   listBox.ListBoxValue = new ListOption[] { listBox.Options[1] }; // select second option

   // set the value of a drop down 
   DropDownListField dropDown = document.Fields["ComboBox8"] as DropDownListField;
   dropDown.DropDownListValue = dropDown.Options[1]; // select second option

   // save PDF
   using (var fileOut = new FileStream("filled.pdf", FileMode.Create, FileAccess.Write))
   {
      document.Write(fileOut);
   }
}
Using fileIn As New FileStream("..\..\..\inputDocuments\fields.pdf", FileMode.Open, FileAccess.Read)
    Dim document As New Document(fileIn)

    Dim textField As TextField = TryCast(document.Fields("Text1"), TextField)
    textField.Value = "Hello"

    Dim checkBox As CheckBoxField = TryCast(document.Fields("Check Box2"), CheckBoxField)
    checkBox.CheckBoxValue = CheckState.[On]

    Dim radioButton As RadioButtonField = TryCast(document.Fields("Radio Button4"), RadioButtonField)
    radioButton.RadioButtonValue = radioButton.Options(1)
    ' second option
    Dim listBox As ListBoxField = TryCast(document.Fields("List Box7"), ListBoxField)
    listBox.ListBoxValue = New ListOption() {listBox.Options(1)}
    ' second option
    Dim dropDown As DropDownListField = TryCast(document.Fields("Combo Box8"), DropDownListField)
    dropDown.DropDownListValue = dropDown.Options(1)
    ' second option
    Using fileOut As New FileStream("..\..\fillfields.pdf", FileMode.Create, FileAccess.Write)
        document.Write(fileOut)
    End Using
End Using