Create, Fill, or Edit Fillable PDF Forms Programmatically with C#

Fill PDF Form

PDF forms are frequently used to collect data and information. For example, Questionnaires are usually designed to collect responses for survey purposes. We interact with different fillable PDF forms in today’s digital world. Considering the huge scope and importance of PDF forms, Aspose.PDF for .NET API supports many features to work with PDF forms. Let us explore the following use cases using C# language in this article:

Create Fillable PDF Forms using C#

You can create a fillable PDF form from scratch using Aspose.PDF for .NET API. Here we will consider the basic example of adding two TextBoxField instances and RadioButton. However, one of the TextBoxField is single line while the other one is multi-line. Below are the steps to create a form in PDF document:

  1. Create an instance of Document class
  2. Add a blank page in PDF document
  3. Add TextBox Field in the form
  4. Set different properties of the fields including Font, Border etc.
  5. Add Radio Button in the form
  6. Save PDF document

Following code snippet shows how to create form in PDF using C#:

The screenshot below shows output PDF document containing form fields as specified in above code snippet:

PDF form

Fill, Modify, or Delete Form Fields in Existing PDF using C#

As we have explored creating a form in PDF document using C#, Aspose.PDF for.NET API supports working with existing PDF forms as well. Let us discuss the following features of the API.

i) Fill a Form Field in Existing PDF file using C#

For filling the PDF forms, we will continue with the PDF document that was created in the example above. Below are the steps to fill fields in an existing PDF document:

  1. Load source PDF document
  2. Get Textbox Fields and fill values
  3. Get Radio button field and select an option from the group
  4. Save filled PDF form

Following code snippet follows these steps and explains how to fill fields in a PDF document using C#:

Below screenshot shows filled form fields of PDF form using C#:

Fillable PDF

ii) Modify a Form Field in PDF Document using C#

Sometimes you may need to change value in any field of a PDF form. Changing a value in a form field is a basic use case that can be achieved with below steps:

  1. Load the PDF form
  2. Get a specific field using its name
  3. Modify field value
  4. Save the updated PDF document

Following code snippet shows how to change a value in a form field of PDF document:

It is noteworthy here that you can not only change the value of the form but other properties can be updated as well. For instance, the field has been marked as Read Only in the code snippet above.

iii) Delete a Form Field in Existing PDF File using C#

We have already learned about adding and filling PDF form fields. Now let us explore removing a form field. You need to follow the steps below:

  1. Load the PDF document
  2. Call Delete method with the name of the form field
  3. Save PDF Document

Following code snippet shows how to delete form field from PDF file using C#:

Preserve Extended Rights of PDF Forms using C#

A PDF form might have extended rights, also referred to as extended features, which you would want to preserve during form manipulation. You should save it incrementally while following the steps below:

  • Load the PDF document in Stream
  • Work with form
  • Save the file without any parameter

The following C# code snippet explains how to preserve extended rights of PDF form:

Use JavaScript in PDF Form using C#

You can use JavaScript in PDF form fields with Aspose.PDF for .NET API. Let us follow the below steps to achieve this requirement:

  1. Initiate an instance of Document class
  2. Add a TextBoxField on the first page at specific page coordinates
  3. Set up JavaScript
  4. Specify document action
  5. Save PDF document

Following code snippet shows how to add JavaScript in PDF form using C#:

The JavaScript gets the current date and time of the system when PDF document is opened and that value is populated into a text box.


In this article, we have learned different aspects of working with form in PDF documents. Creating, filling or editing PDF forms is simple with Aspose.PDF for .NET API. The API offers many such exciting features to work with different files. Let us know your feedback or comments via Free Support Forum.

See Also

Fill, Create, or Edit Fillable PDF Forms Programmatically using Java