Create, Fill, and Edit Fillable PDF Forms Using C# – A Complete Guide
Tags: fileformats, dotnet, pdf, forms
Published: 2023-11-15 07:10:19

---
title: Create, Fill, and Edit Fillable PDF Forms Using C# – A Complete Guide
published: true
date: 2023-08-09 17:15:11 UTC
tags: fileformats, dotnet, pdf, forms
canonical_url: https://www.syncfusion.com/blogs/post/create-fill-edit-pdf-forms-using-csharp.aspx
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hfp4g56r3s6tgfjmdomc.png
---
PDF forms allow users to input and submit data in a structured format. These forms are popular because they are easy to use and can be filled out electronically, reducing the need for paper and manual data entry. They can also be saved and shared electronically, making them convenient for individuals and organizations.

The [Syncfusion .NET PDF Library](https://www.syncfusion.com/document-processing/pdf-framework/net ".NET PDF Library") provides comprehensive support for creating, customizing, and managing form fields in PDF documents.

This article will explore several use cases of PDF forms and how they can be implemented using the Syncfusion .NET PDF Library.

**Agenda**

- [Create a new, fillable PDF form](#Create)
- [Fill form fields in a PDF](#Fill)
- [Modify form fields in a PDF](#Modify)
- [Remove form fields from a PDF](#Remove)
- [Create a signature field and sign a PDF](#Create_a)
- [Restrict editing capability of form fields](#Restrict)
- [Import and export PDF forms data](#Import)
- [Retain extended rights of PDF forms](#Retain)
- [Utilize JavaScript actions in PDF forms](#Utilize)

## <a name="Create">Create a new, fillable PDF form</a>

Syncfusion’s .NET PDF Library allows users to easily create forms (Acroforms) in PDF documents with various form fields. You can include text boxes, combo boxes, radio buttons, list boxes, checkboxes, signature fields, buttons, and more in the PDF form.

Let’s create a simple form with a text box and radio button fields in a PDF document:

1.First, create a new PDF document using the [PdfDocument](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.PdfDocument.html#Syncfusion_Pdf_PdfDocument__ctor "PdfDocument () Constructor for File Formats") class.
2.Add a new blank page using the [PdfPage](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.PdfPage.html#Syncfusion_Pdf_PdfPage__ctor "PdfPage() Constructor for File Formats") class.
3.Create text box fields to collect the name, email address, and phone number using the [PdfTextBoxField](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Interactive.PdfTextBoxField.html "PdfTextBoxField Class for File Formats") class.
4.Then, create the radio button fields for gender selection using the [PdfRadioButtonListField](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Interactive.PdfRadioButtonListField.html "PdfRadioButtonListField Class for File Formats") class and add the list items using the [PdfRadioButtonListItem](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Interactive.PdfRadioButtonListItem.html "PdfRadioButtonListItem Class for File Formats") class.
5.Finally, save the PDF document using the [Save](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Parsing.PdfLoadedDocument.html#Syncfusion_Pdf_Parsing_PdfLoadedDocument_Save_System_IO_Stream_ "Save(Stream) method for File Formats") method.

The following code example shows how to create a simple form in a PDF document using C#.

```csharp
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a new page to the PDF document.
PdfPage page = document.Pages.Add();
//Set the standard font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 16);
//Draw the string.      
page.Graphics.DrawString("Job Application", font, PdfBrushes.Black, new PointF(250, 0));
font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
page.Graphics.DrawString("Name", font, PdfBrushes.Black, new PointF(10, 20));

//Create a text box field for the name.
PdfTextBoxField textBoxField1 = new PdfTextBoxField(page, "Name");
textBoxField1.Bounds = new RectangleF(10, 40, 200, 20);
textBoxField1.ToolTip = "Name";
document.Form.Fields.Add(textBoxField1);

page.Graphics.DrawString("Email address", font, PdfBrushes.Black, new PointF(10, 80));
//Create a text box field for the email address.
PdfTextBoxField textBoxField3 = new PdfTextBoxField(page, "Email address");
textBoxField3.Bounds = new RectangleF(10, 100, 200, 20);
textBoxField3.ToolTip = "Email address";
document.Form.Fields.Add(textBoxField3);

page.Graphics.DrawString("Phone", font, PdfBrushes.Black, new PointF(10, 140));
//Create a text box field for the phone number.
PdfTextBoxField textBoxField4 = new PdfTextBoxField(page, "Phone");
textBoxField4.Bounds = new RectangleF(10, 160, 200, 20);
textBoxField4.ToolTip = "Phone";
document.Form.Fields.Add(textBoxField4);

page.Graphics.DrawString("Gender", font, PdfBrushes.Black, new PointF(10, 200));
//Create a radio button for gender.
PdfRadioButtonListField employeesRadioList = new PdfRadioButtonListField(page, "Gender");
document.Form.Fields.Add(employeesRadioList);
page.Graphics.DrawString("Male", font, PdfBrushes.Black, new PointF(40, 220));
PdfRadioButtonListItem radioButtonItem1 = new PdfRadioButtonListItem("Male");
radioButtonItem1.Bounds = new RectangleF(10, 220, 20, 20);
page.Graphics.DrawString("Female", font, PdfBrushes.Black, new PointF(140, 220));
PdfRadioButtonListItem radioButtonItem2 = new PdfRadioButtonListItem("Female");
radioButtonItem2.Bounds = new RectangleF(110, 220, 20, 20);
employeesRadioList.Items.Add(radioButtonItem1);
employeesRadioList.Items.Add(radioButtonItem2);

//Create file stream.
using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite))
{
    //Save the PDF document to file stream.
    document.Save(outputFileStream);
}
//Close the document.
document.Close(true);
```

Running this code example will generate a PDF that closely resembles the image displayed below.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/08/Creating-a-PDF-form-using-Syncfusion-.NET-PDF-Library.png" alt="Creating a PDF form using Syncfusion .NET PDF Library" style="width:100%">

  <figcaption>Creating a PDF form using Syncfusion .NET PDF Library</figcaption>

</figure>

## <a name="Fill">Fill form fields in a PDF</a>

We can use the [TryGetField](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Parsing.PdfLoadedFormFieldCollection.html#Syncfusion_Pdf_Parsing_PdfLoadedFormFieldCollection_TryGetField_System_String_Syncfusion_Pdf_Parsing_PdfLoadedField__"TryGetField(String, out PdfLoadedField) property for File Formats") method to get a form field from an existing document using the field name. This method helps us determine the field’s availability within the form by returning a Boolean value.

Follow these steps to fill in the form fields in a PDF document:

1.Use the [PdfLoadedDocument](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Parsing.PdfLoadedDocument.html "PdfLoadedDocument Class for File Formats") class to load the created PDF document.
2.Get the form from the PDF using the [PdfLoadedForm](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Parsing.PdfLoadedForm.html "PdfLoadedForm Class for File Formats") class.
3.Now, get the form field collections using the [PdfLoadedFormFieldCollection](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Parsing.PdfLoadedFormFieldCollection.html "PdfLoadedFormFieldCollection Class for File Formats") class.
4.Use the [TryGetField](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Parsing.PdfLoadedFormFieldCollection.html#Syncfusion_Pdf_Parsing_PdfLoadedFormFieldCollection_TryGetField_System_String_Syncfusion_Pdf_Parsing_PdfLoadedField__"TryGetField(String, out PdfLoadedField) property for File Formats") method to obtain the form fields, such as text boxes and checkboxes, and then fill them with the necessary information.
5.Finally, save the filled PDF document using the **Save** method.

The following code example shows how to fill form fields in a PDF document.

```csharp
//Load the PDF document.
FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
//Load the form from the loaded PDF document.
PdfLoadedForm form = loadedDocument.Form;
//Load the form field collections from the form.
PdfLoadedFormFieldCollection fieldCollection = form.Fields as PdfLoadedFormFieldCollection;
PdfLoadedField loadedField = null;

//Get and fill the field using TryGetField Methodmethod.
if (fieldCollection.TryGetField("Name", out loadedField))
{
    (loadedField as PdfLoadedTextBoxField).Text = "Simons";
}
if (fieldCollection.TryGetField("Email address", out loadedField))
{
    (loadedField as PdfLoadedTextBoxField).Text = "simonsbistro@outlook.com";
}
if (fieldCollection.TryGetField("Phone", out loadedField))
{
    (loadedField as PdfLoadedTextBoxField).Text = "31 12 34 56";
}
if (fieldCollection.TryGetField("Gender", out loadedField))
{
    (loadedField as PdfLoadedRadioButtonListField).SelectedIndex = 0;
}

//Create file stream.
using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite))
{
    //Save the PDF document to file stream.
    loadedDocument.Save(outputFileStream);
}
//Close the document.
loadedDocument.Close(true);
```

This code generates a pre-filled PDF with your designated form field values.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/08/Filling-the-form-fields-in-a-PDF-document.png" alt="Filling the form fields in a PDF document" style="width:100%">

  <figcaption>Filling the form fields in a PDF document</figcaption>

</figure>

**Note:** The specific layout and design of the filled PDF document may vary based on the original PDF document and the values set for the form fields.

## <a name="Modify">Modifying a form field in a PDF </a>

You can also modify an existing form field and its properties like bounds, text, color, and border. To do so, please follow these steps:

1.Use the **PdfLoadedDocument** class to load an existing PDF document.
2.Get the existing form in a PDF using the **PdfLoadedForm** class.
3.Get the required form fields from the **PdfFormFieldCollection**.
4.Modify the text box form field properties.
5.Finally, save the PDF document using the **Save** method.

The following code example illustrates how to modify an existing form field in a PDF document.

```csharp
//Load the PDF document.
FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
//Get the loaded form.
PdfLoadedForm loadedForm = loadedDocument.Form;

//Get the loaded form field and modify the properties.
PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[0] as PdfLoadedTextBoxField;
RectangleF newBounds = new RectangleF(200, 60, 300, 30);
loadedTextBoxField.Bounds = newBounds;
loadedTextBoxField.Text = "John";
loadedTextBoxField.BackColor = Color.LightYellow;
loadedTextBoxField.BorderColor = Color.Red;

//Create file stream.
using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite))
{
    //Save the PDF document to file stream.
    loadedDocument.Save(outputFileStream);
}
//Close the document.
loadedDocument.Close(true);
```

By executing this code example, we will get a PDF like the following image.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/08/Modifying-a-form-field-in-a-PDF-document.png" alt="Modifying a form field in a PDF document" style="width:100%">

  <figcaption>Modifying a form field in a PDF document</figcaption>

</figure>

## <a name="Remove">Removing form fields from a PDF</a>

You can easily remove form fields from a PDF document by following these steps:

1.Use the **PdfLoadedDocument** class to load a PDF document.
2.Get the form using the **PdfLoadedForm** class.
3.Now, remove the required form field from the index using the [RemoveAt](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Interactive.PdfFieldCollection.html#Syncfusion_Pdf_Interactive_PdfFieldCollection_RemoveAt_System_Int32_ "RemoveAt(Int32) property for File Formats") method or specify the field name in the [Remove](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Interactive.PdfFieldCollection.html#Syncfusion_Pdf_Interactive_PdfFieldCollection_Remove_Syncfusion_Pdf_Interactive_PdfField_ "Remove(PdfField) property for File Formats") method of the [PdfFieldCollection](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Interactive.PdfFieldCollection.html "PdfFieldCollection class for File Formats") class.
4.Then, save the PDF document using the **Save** method.

The following code illustrates how to remove form fields from a PDF document.

```csharp
//Load the PDF document.
FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
//Get the loaded form.
PdfLoadedForm loadedForm = loadedDocument.Form;

//Load the text box field.
PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[2] as PdfLoadedTextBoxField;
//Remove the field.
loadedForm.Fields.Remove(loadedTextBoxField);
//Remove the field at index 1.
loadedForm.Fields.RemoveAt(1);

//Create file stream.
using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite))
{
    //Save the PDF document to file stream.
    loadedDocument.Save(outputFileStream);
}
//Close the document.
loadedDocument.Close(true);
```

By executing this code example, we will get the PDF in the following image.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/08/Removing-forms-fields-from-a-PDF-document.png" alt="Removing forms fields from a PDF document" style="width:100%">

  <figcaption>Removing forms fields from a PDF document</figcaption>

</figure>

## <a name="Create_a">Create a signature field and sign the PDF document</a>

The Syncfusion .NET PDF Library helps create signature fields for signing PDF documents with ease.

### Adding a signature field to a PDF 

Follow these steps to create a signature field in a PDF document using Syncfusion’s .NET PDF Library:

1.Create a new PDF document using the [PdfDocument](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.PdfDocument.html#Syncfusion_Pdf_PdfDocument__ctor "PdfDocument() Constructors for File Formats") class.
2.Add a new blank page using the [PdfPage](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.PdfPage.html#Syncfusion_Pdf_PdfPage__ctor "PdfPage() Constructors for File Formats") class.
3.Create a new signature field using the [PdfSignatureField](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Interactive.PdfSignatureField.html "PdfSignatureField Class for File Formats") class.
4.Save the PDF document using the **Save** method.

The following code example illustrates creating a signature field in a new PDF document.

```csharp
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a new page to the PDF document.
PdfPage page = document.Pages.Add();

//Create a PDF sSignature field.
PdfSignatureField signatureField = new PdfSignatureField(page, "Signature");
//Set properties to the signature field.
signatureField.Bounds = new RectangleF(0, 100, 90, 20);
signatureField.ToolTip = "Signature";
//Add the form field to the document.
document.Form.Fields.Add(signatureField);

//Create file stream.
using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite))
{
    //Save the PDF document to file stream.
    document.Save(outputFileStream);
}
//Close the document.
document.Close(true);
```

By executing this code example, you will get a PDF like in the following image.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/08/Adding-signature-field-in-a-PDF.png" alt="Adding signature field in a PDF" style="width:100%">

  <figcaption>Adding a signature field in a PDF</figcaption>

</figure>

### Digitally sign the PDF document

For how to digitally sign a PDF and verify signatures, [refer to this blog](https://www.syncfusion.com/blogs/post/create-validate-pdf-digital-signatures-csharp.aspx "Blog: Digitally Sign and Verify Signatures in PDF Files Using C#: A Complete Guide").

## <a name="Restrict">Restrict editing capabilities of form fields</a>

PDF forms are an excellent way to gather information from users. However, you may want to restrict the editing capability of all or certain form fields to prevent unintended modifications. This can be done by flattening the PDF document or marking the form or field as read-only.

### Flattening form fields

The Syncfusion .NET PDF Library supports [flattening](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Interactive.PdfField.html#Syncfusion_Pdf_Interactive_PdfField_Flatten "Flatten Property for File Formats") a specific form field or entire form by removing the existing form field and replacing it with graphical objects that resemble the form field but cannot be edited.

Here are the steps to flatten the form fields in a PDF document:

1.Use the **PdfLoadedDocument** class to load a PDF document.
2.Get the form using the **PdfLoadedForm** class.
3.Get the form field collections using the **PdfLoadedFormFieldCollection** class.
4.Now, flatten the whole form using the [Flatten](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Interactive.PdfField.html#Syncfusion_Pdf_Interactive_PdfField_Flatten "Flatten Property for File Formats") property.
5.Finally, save the PDF document using the **Save** method.

The following code example illustrates how to flatten the form fields in a PDF document.

``csharp
//Load the PDF document.
FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
//Get the loaded form.
PdfLoadedForm loadedForm = loadedDocument.Form;
PdfLoadedFormFieldCollection fields = loadedForm.Fields;
//Flatten the whole form.
loadedForm.Flatten = true;

//Create file stream.
using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite))
{
    //Save the PDF document to file stream.
    loadedDocument.Save(outputFileStream);
}
//Close the document.
loadedDocument.Close(true);
```

### Marking the PDF form read-only

We can restrict the editing of a PDF form by marking it as read-only:

1.Use the **PdfLoadedDocument** class to load a PDF document.
2.Get the form using the **PdfLoadedForm** class.
3.Set the form to read-only using the [ReadOnly](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Interactive.PdfField.html#Syncfusion_Pdf_Interactive_PdfField_ReadOnly "ReadOnly Property for File Formats") property.
4.Then, save the PDF document using the **Save** method.

Refer to the following code example.

```csharp
//Load the PDF document.
FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
//Get the loaded form.
PdfLoadedForm loadedForm = loadedDocument.Form;
//Set the form as read-only.
loadedForm.ReadOnly = true;

//Create file stream.
using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite))
{
    //Save the PDF document to file stream.
    loadedDocument.Save(outputFileStream);
}
//Close the document.
loadedDocument.Close(true);
```

By executing this code example, you will get a PDF like in the following image.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/08/Restricting-editing-capabilities-of-a-PDF-form.png" alt="Restricting editing capabilities of a PDF form" style="width:100%">

  <figcaption>Restricting editing capabilities of a PDF form</figcaption>

</figure>

## <a name="Import">Import and export PDF form data</a>

PDF forms are commonly used to collect data from users. Once the data is collected, it may need to be exported or imported for further analysis or processing. The Syncfusion .NET PDF Library supports importing and exporting PDF form data in various formats such as **FDF** , **XFDF** , **JSON** , and **XML**. This makes it easy to integrate form data with other apps and systems.

### Import form field data to PDF

The following steps illustrate how to import form field data to a PDF document:  

1.Use the **PdfLoadedDocument** class to load a PDF document.
2.Get the form in the PDF using the **PdfLoadedForm** class.
3.Import the form field data from an FDF file to the PDF using the [ImportDataFDF](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Parsing.PdfLoadedForm.html#Syncfusion_Pdf_Parsing_PdfLoadedForm_ImportDataFDF_System_Byte___"ImportDataFDF(Byte[]) Property for File Formats") method.
4.Finally, save the modified PDF document using the **Save** method.

Refer to the following code example.

```csharp
//Load the PDF document.
FileStream docStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
//Load the existing form.
PdfLoadedForm loadedForm = loadedDocument.Form;
//Load the FDF file.
FileStream fileStream = new FileStream("Input.fdf", FileMode.Open, FileAccess.Read);
//Import the FDF stream.
loadedForm.ImportDataFDF(fileStream, true);

//Create file stream.
using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite))
{
    //Save the PDF document to file stream.
    loadedDocument.Save(outputFileStream);
}
//Close the document.
loadedDocument.Close(true);
```

By executing this code example, you will get a PDF like in the following image.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/08/Importing-form-fields-from-FDF-file-to-PDF-form.png" alt="Importing form fields from FDF file to PDF form" style="width:100%">

  <figcaption>Importing form fields from FDF file to PDF form</figcaption>

</figure>

### Export form field data from PDF

The following steps illustrate how to export PDF form field data to an XML file:

1.Use the **PdfLoadedDocument** class to load a PDF document.
2.Get the form from the PDF using the **PdfLoadedForm** class.
3.Export the PDF form field data to an XML file using the [ExportData](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Parsing.PdfLoadedForm.html#Syncfusion_Pdf_Parsing_PdfLoadedForm_ExportData_System_IO_Stream_Syncfusion_Pdf_Parsing_DataFormat_System_String_ "ExportData(Stream, DataFormat, String) Property for File Formats") You can specify the format of the exported data using the [DataFormat](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Parsing.DataFormat.html "Enum DataFormat Field for File Formats") enum.
4.Save the modified PDF document using the **Save** method.

Refer to the following code example.

```csharp
//Load the PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
//Load an existing form. 
PdfLoadedForm loadedForm = loadedDocument.Form;
//Create memory stream.
MemoryStream ms = new MemoryStream();
//Create the XML file. 
FileStream stream = new FileStream("Export.xml", FileMode.Create, FileAccess.ReadWrite);
//Export the existing PDF form fields data to the XML file. 
loadedForm.ExportData(stream, DataFormat.Xml, "AcroForm1");
//Close the document.
loadedDocument.Close(true);
```

By executing this code example, you will get XML like in the following image.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/08/Exporting-PDF-form-field-data-to-an-XML-file.png" alt="Exporting PDF form field data to an XML file" style="width:100%">

  <figcaption>Exporting PDF form field data to an XML file</figcaption>

</figure>

## <a name="Retain">Retain extended rights of PDF forms</a>

Extended features in a PDF form refer to additional capabilities that are not part of the standard PDF specification. These features allow users to do more with the form than just filling out fields and submitting data.

The Syncfusion .NET PDF Library supports preserving extended rights in PDF forms when performing actions like filling the form fields.

You can fill the reader-extended PDF document by following these steps:

1.Use the **PdfLoadedDocument** class to load the extended featured PDF document.
2.Get the form from the PDF using the **PdfLoadedForm** class.
3.Get the form field collections using the **PdfLoadedFormFieldCollection** class.
4.Use the [TryGetField](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Parsing.PdfLoadedFormFieldCollection.html#Syncfusion_Pdf_Parsing_PdfLoadedFormFieldCollection_TryGetField_System_String_Syncfusion_Pdf_Parsing_PdfLoadedField__"TryGetField(String, out PdfLoadedField) Property for File Formats") method to obtain the **First Name** , **Last Name,** and **Email address** form fields and then fill them with the necessary information.
5.Finally, save the PDF document (Extended rights preserved) using the **Save** method.

Refer to the following code example.

```csharp
//Load a PDF.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
//Load the form from the loaded document.
PdfLoadedForm loadedForm = loadedDocument.Form;
loadedForm.SetDefaultAppearance(false);
//Load the form field collections from the form.
PdfLoadedFormFieldCollection fieldCollection = loadedForm.Fields as PdfLoadedFormFieldCollection;
PdfLoadedField loadedField = null;

//Get the field using TryGetField method.
if (fieldCollection.TryGetField("First Name", out loadedField))
{
    (loadedField as PdfLoadedTextBoxField).Text = "Simons";
}
if (fieldCollection.TryGetField("Last Name", out loadedField))
{
    (loadedField as PdfLoadedTextBoxField).Text = "Bistro";
}
if (fieldCollection.TryGetField("Email Address", out loadedField))
{
    (loadedField as PdfLoadedTextBoxField).Text = "simonsbistro@outlook.com";
}

//Create file stream.
using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite))
{
    //Save the PDF document to file stream.
    loadedDocument.Save(outputFileStream);
}
//Close the document.
loadedDocument.Close(true);
```

By executing this code example, you will get a PDF like in the following image.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/08/Retaining-extended-rights-in-a-PDF-form.png" alt="Retaining extended rights in a PDF form" style="width:100%">

  <figcaption>Retaining extended rights in a PDF form</figcaption>

</figure>

## <a name="Utilize">Utilizing JavaScript actions in PDF forms</a>

The Syncfusion .NET PDF Library also supports adding JavaScript actions to the form fields using the [PdfJavaScriptAction](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Interactive.PdfJavaScriptAction.html "PdfJavaScriptAction Class for File Formats") class:

1.Create a new PDF document using the [PdfDocument](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.PdfDocument.html#Syncfusion_Pdf_PdfDocument__ctor "PdfDocument() Constructors for File Formats") class.
2.Then, add a new blank page in it using the [PdfPage](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.PdfPage.html#Syncfusion_Pdf_PdfPage__ctor "PdfPage() Constructors for File Formats") class.
3.Use the [PdfButtonField](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Interactive.PdfButtonField.html "PdfButtonField Class for File Formats") class to create a new button field.
4.Set the JavaScript action for the submit button using the [PdfJavaScriptAction](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Interactive.PdfJavaScriptAction.html "PdfJavaScriptAction Class for File Formats") class.
5.Finally, save the PDF document using the **Save** method.

Refer to the following code example.

```csharp
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Create a new page.
PdfPage page = document.Pages.Add();

//Create a new PdfButtonField.
PdfButtonField submitButton = new PdfButtonField(page, "submitButton");
submitButton.Bounds = new RectangleF(25, 160, 100, 20);
submitButton.Text = "Apply";
submitButton.BackColor = new PdfColor(181, 191, 203);

//Create a new PdfJavaScriptAction.
PdfJavaScriptAction scriptAction = new PdfJavaScriptAction("app.alert(\"You are looking at form fields action of PDF document\")");
//Set the scriptAction to submitButton.
submitButton.Actions.MouseDown = scriptAction;

//Add the submit button to the new document.
document.Form.Fields.Add(submitButton);

//Create file stream.
using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite))
{
    //Save the PDF document to file stream.
    document.Save(outputFileStream);
}
//Close the document.
document.Close(true);
```

By executing this code example, you will get a PDF like in the following screenshot.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/08/Adding-JavaScript-actions-to-PDF-form.png" alt="Adding JavaScript actions to PDF form" style="width:100%">

  <figcaption>Adding JavaScript actions to PDF form</figcaption>

</figure>

## GitHub reference

For more details, refer to the [create, fill, and edit fillable PDF forms using the C#](https://github.com/SyncfusionExamples/Create-fill-or-edit-fillable-PDF-forms-csharp "create, fill, and edit fillable PDF forms using the C# GitHub demo") demo on GitHub.

## Conclusion

Thanks for reading! In this blog, we’ve seen how to create, fill, and edit forms in PDF documents using the [Syncfusion .NET PDF Library](https://www.syncfusion.com/document-processing/pdf-framework/net/pdf-library ".NET PDF Library"). Try out the steps in this blog post and leave your feedback in the comments section below.

Take a moment to look at the [PDF forms documentation](https://help.syncfusion.com/file-formats/pdf/working-with-forms "Getting Started on How to Work with PDF Forms"), where you can find other options and features, all with accompanying code examples.

For questions, you can contact us through our [support forum](https://www.syncfusion.com/forums "Syncfusion Support Forum"), [support portal](https://support.syncfusion.com/ "Syncfusion Support Portal"), or [feedback portal](https://www.syncfusion.com/feedback/pdf "Syncfusion Feedback Portal"). We are always happy to assist you!

## Related Blog

- [4 Simple Steps to Create Thumbnail Images for Excel Documents in C#](https://www.syncfusion.com/blogs/post/excel-to-thumbnail-conversion-csharp.aspx "Blog: 4 Simple Steps to Create Thumbnail Images for Excel Documents in C#")
- [What’s New in 2023 Volume 2: File-Format Libraries](https://www.syncfusion.com/blogs/post/whats-new-2023-volume-2-file-format-libraries.aspx "Blog: What’s New in 2023 Volume 2: File-Format Libraries")
- [Rotate Pages, Text, Tables, and Images in a PDF Using C#](https://www.syncfusion.com/blogs/post/rotate-page-text-table-image-pdf-csharp.aspx "Blog: Rotate Pages, Text, Tables, and Images in a PDF Using C#")
- [Easily Create, Update, and Remove Bookmarks in PDFs Using C#](https://www.syncfusion.com/blogs/post/bookmarks-in-pdf-csharp.aspx "Blog: Easily Create, Update, and Remove Bookmarks in PDFs Using C#")