How to Fill PDF Form Fields using C#

This brief tutorial shares details about how to fill PDF form fields using C#. A PDF file can have different types of form fields like textbox, radio button, and a combo box. To programmatically fill PDF form C# code demonstrates accessing the textbox form field and then updating the value and formatting in it.

Steps to Fill PDF Form Fields using C#

  1. Setup your solution to add Aspose.PDF from NuGet package manager
  2. Load the sample PDF file into the Document object containing textbox form fields
  3. Get a reference to the form field by providing the field name and cast as TextBoxField
  4. Set the new text in the textbox field using the Value property
  5. Set the text color and text alignment of the textbox field
  6. Save the updated PDF file with new values in the form fields

These steps provide information on how using C# fill PDF form fields by sharing configuration details and then stepwise process to load the source PDF file and access the form fields in it. In the subsequent steps, the value and formatting of the textbox field are updated. Finally, the updated PDF file is saved on the disk.

Code to Fill PDF Form Fields using C#

Using C# fill out PDF form operation is demonstrated along with the optional formatting step. We can access the form fields by providing the field name using Document.Form[“FieldName”] and then cast it into the respective field types i.e. TextBoxField, RadioButtonField, or ComboBoxField. Once the target field is selected, you can not only set its value but also change its properties as well like appearance, border, color, contents, height, width, horizontal and vertical text alignment to name a few.

This tutorial guides how using C# fill PDF form automatically. If you want to learn, how to flatten PDF form fields, refer to the article on how to flatten PDF form fields in C#.

 English