---
title: "PDF form field actions in C# | Nutrient .NET SDK"
canonical_url: "https://www.nutrient.io/guides/dotnet/annotations/pdf-actions-support/"
md_url: "https://www.nutrient.io/guides/dotnet/annotations/pdf-actions-support.md"
last_updated: "2026-05-21T17:12:02.199Z"
description: "Learn how to add and customize PDF actions using C# and .NET for form fields, including navigation, launching apps, and running JavaScript."
---

# Add PDF actions using C# in form fields

PDF actions enable you to perform the following tasks:

- [Navigate to another page](#navigating-to-a-specified-page)

- [Open a new PDF](#navigating-to-a-specified-page-of-a-different-pdf)

- [Launch an application](#launching-an-application)

- [Open a link to a website](#opening-a-link-to-a-website)

- [Run JavaScript](#running-javascript)

Actions are triggered by annotations, form fields, or bookmarks. To create an action in a PDF document, use the following steps:

1. Create an annotation as a trigger for the action.

2. Create any action with one of the following methods:
   - [`NewActionGoTo`](#navigating-to-a-specified-page)

   - [`NewActionGoToR`](#navigating-to-a-specified-page-of-a-different-pdf)

   - [`NewActionLaunch`](#launching-an-application)

   - [`NewActionURI`](#opening-a-link-to-a-website)

   - [`NewActionJavaScript`](#running-a-javascript)

3. Set the action to the annotation.

4. Save the PDF document to a file.

## Navigating to a specified page

To create an action that navigates to a specified PDF page, use the following steps:

1. Create a `GdPicturePDF` object.

2. Load the PDF file with the [`LoadFromFile` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~LoadFromFile.html).

3. Set the origin of the coordinate system with the [`SetOrigin` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetOrigin.html). This method requires the [`PDFOrigin` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.PdfOrigin.html).

4. Set the measurement unit with the [`SetMeasurementUnit` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetMeasurementUnit.html) to specify the form field’s dimensions and position. This method uses the [`PdfMeasurementUnit` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.PdfMeasurementUnit.html).

5. Set the PDF page where you want to place the form field with the [`SelectPage` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SelectPage.html).

6. Add any type of annotation.

7. Create a new action with the [`NewActionGoTo` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~NewActionGoTo.html). It uses the following parameters:
   - `DestinationType` — A member of the [`PdfDestinationType` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.PdfDestinationType.html) that specifies the way the destination page is displayed relative to the window.
   - `Page` — The destination page number.
   - `Left` — The left coordinate of the document window’s position according to the specified `DestinationType` parameter.
   - `Right` — The right coordinate of the document window’s position according to the specified `DestinationType` parameter.
   - `Bottom` — The bottom coordinate of the document window’s position according to the specified `DestinationType` parameter.
   - `Top` — The top coordinate of the document window’s position according to the specified `DestinationType` parameter.
   - `Zoom` — The magnification factor used to display the destination page. To get the 150 percent magnification, use `1.5`. To get the current magnification, set this parameter to `0`.
   - `RetainLeft` — Optional: To keep the left coordinate at the current display, set this parameter to `true`.
   - `RetainRight` — Optional: To keep the right coordinate at the current display, set this parameter to `true`.

8. Set the action to the annotation with the [`SetAnnotationAction` method]. It requires the annotation and the action IDs.

9. Save the PDF document to a file with the [`SaveToFile` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SaveToFile.html).

The display of the destination page uses the following rules:

- The `Left`, `Right`, `Bottom`, `Top`, and `Zoom` parameters only have an effect when the `DestinationType` parameter is set to `PdfDestinationType.DestinationTypeXYZ`.

- The `Zoom` parameter is the last parameter executed by the method.

The return value of the `NewActionGoTo` method is the action’s ID. It’s required to assign the trigger element of the newly created action.

To create an action that navigates to the third page of the PDF document, use the following code:

### C#

```csharp

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Set the origin of the coordinate system.
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
// Set the measurement unit to centimeters.
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
// Select the second PDF page.
gdpicturePDF.SelectPage(2);
// Create a new action.
int actionID = gdpicturePDF.NewActionGoTo(PdfDestinationType.DestinationTypeXYZ, 3, 0, 0, 5, 0, 1.5f);

gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");

```

### VB.NET

```vb

Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Set the origin of the coordinate system.
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
    ' Set the measurement unit to centimeters.
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
    ' Select the second PDF page.
    gdpicturePDF.SelectPage(2)
    ' Create a new action.
    Dim actionID As Integer = gdpicturePDF.NewActionGoTo(PdfDestinationType.DestinationTypeXYZ, 3, 0, 0, 5, 0, 1.5F)

    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
End Using

```

#### Used methods

- [`AddPushButtonFormField`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddPushButtonFormField.html)

- [`AddStandardFont`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddStandardFont.html)

- [`LoadFromFile`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~LoadFromFile.html)

- [`NewActionGoTo`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~NewActionGoTo.html)

- [`SaveToFile`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SaveToFile.html)

- [`SelectPage`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SelectPage.html)

- [`SetFormFieldAction`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetFormFieldAction.html)

- [`SetMeasurementUnit`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetMeasurementUnit.html)

- [`SetOrigin`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetOrigin.html)

#### Related topics

- [Load a file](/guides/dotnet/load-a-file.md)

- [Save a file](/guides/dotnet/save-a-file.md)

## Navigating to a specified page of a different PDF

To create an action that navigates to a specified page of a different PDF document, use the following steps:

1. Create a `GdPicturePDF` object.

2. Load the PDF file with the [`LoadFromFile` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~LoadFromFile.html).

3. Set the origin of the coordinate system with the [`SetOrigin` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetOrigin.html). This method requires the [`PDFOrigin` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.PdfOrigin.html).

4. Set the measurement unit with the [`SetMeasurementUnit` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetMeasurementUnit.html) to specify the form field’s dimensions and position. This method uses the [`PdfMeasurementUnit` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.PdfMeasurementUnit.html).

5. Set the PDF page where you want to place the form field with the [`SelectPage` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SelectPage.html).

6. Add any type of annotation.

7. Create a new action with the [`NewActionGoToR` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~NewActionGoToR.html). It uses the following parameters:
   - `DestinationType` — A member of the [`PdfDestinationType` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.PdfDestinationType.html) that specifies the way the destination page is displayed relative to the window.
   - `FilePath` — The relative path to the destination file.
   - `NewWindow` — A Boolean value that specifies whether to open the destination PDF document in a new window.
   - `Page` — The destination page number.
   - `Left` — The left coordinate of the document window’s position according to the specified `DestinationType` parameter.
   - `Right` — The right coordinate of the document window’s position according to the specified `DestinationType` parameter.
   - `Bottom` — The bottom coordinate of the document window’s position according to the specified `DestinationType` parameter.
   - `Top` — The top coordinate of the document window’s position according to the specified `DestinationType` parameter.
   - `Zoom` — The magnification factor used to display the destination page. To get the 150 percent magnification, use `1.5`. To get the current magnification, set this parameter to `0`.
   - `RetainLeft` — Optional: To keep the left coordinate at the current display, set this parameter to `true`.
   - `RetainRight` — Optional: To keep the right coordinate at the current display, set this parameter to `true`.

8. Set the action to the annotation with the [`SetAnnotationAction` method]. It requires the annotation and the action IDs.

9. Save the PDF document to a file with the [`SaveToFile` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SaveToFile.html).

The display of the destination page uses the following rules:

- The `Left`, `Right`, `Bottom`, `Top`, and `Zoom` parameters only have an effect when the `DestinationType` parameter is set to `PdfDestinationType.DestinationTypeXYZ`.

- The `Zoom` parameter is the last parameter executed by the method.

The return value of the `NewActionGoToR` method is the action’s ID. It’s required to assign the trigger element of the newly created action.

To create an action that navigates to the third page of the PDF document, use the following code:

### C#

```csharp

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Set the origin of the coordinate system.
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
// Set the measurement unit to centimeters.
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
// Select the second PDF page.
gdpicturePDF.SelectPage(2);
// Create a new action.
int actionID = gdpicturePDF.NewActionGoToR(PdfDestinationType.DestinationTypeXYZ, @"C:\temp\destination.pdf", false, 3, 0, 0, 5, 0, 1.5f);

gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");

```

### VB.NET

```vb

Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Set the origin of the coordinate system.
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
    ' Set the measurement unit to centimeters.
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
    ' Select the second PDF page.
    gdpicturePDF.SelectPage(2)
    ' Create a new action.
    Dim actionID As Integer = gdpicturePDF.NewActionGoToR(PdfDestinationType.DestinationTypeXYZ, @"C:\temp\destination.pdf", false, 3, 0, 0, 5, 0, 1.5f)

    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
End Using

```

#### Used methods

- [`AddPushButtonFormField`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddPushButtonFormField.html)

- [`AddStandardFont`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddStandardFont.html)

- [`LoadFromFile`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~LoadFromFile.html)

- [`NewActionGoToR`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~NewActionGoToR.html)

- [`SaveToFile`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SaveToFile.html)

- [`SelectPage`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SelectPage.html)

- [`SetFormFieldAction`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetFormFieldAction.html)

- [`SetMeasurementUnit`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetMeasurementUnit.html)

- [`SetOrigin`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetOrigin.html)

#### Related topics

- [Load a file](/guides/dotnet/load-a-file.md)

- [Save a file](/guides/dotnet/save-a-file.md)

## Launching an application

To create an action that launches an application, use the following steps:

1. Create a `GdPicturePDF` object.

2. Load the PDF file with the [`LoadFromFile` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~LoadFromFile.html).

3. Set the origin of the coordinate system with the [`SetOrigin` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetOrigin.html). This method requires the [`PDFOrigin` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.PdfOrigin.html).

4. Set the measurement unit with the [`SetMeasurementUnit` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetMeasurementUnit.html) to specify the form field’s dimensions and position. This method uses the [`PdfMeasurementUnit` enumeration].

5. Set the PDF page where you want to place the form field with the [`SelectPage` method].

6. Add any type of annotation.

7. Create a new action with the [`NewActionLaunch` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~NewActionLaunch.html). It uses the following parameters:
   - `FileName` — The application file name.
   - `DefaultDirectory` — Specifies the default directory in a standard DOS syntax. It’s a Windows-specific parameter. If you aren’t sure what value to assign, use an empty string.
   - `Parameters` — A parameter string passed to the application. It’s a Windows-specific parameter. If you aren’t sure what value to assign, use an empty string.
   - `Operation` — A member of the [`PdfActionLaunchOperation` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.PdfActionLaunchOperation.html). It’s a Windows-specific parameter. If you aren’t sure what value to assign, set it to `PdfActionLaunchOperation.ActionLaunchOperationUndefined`.
   - `NewWindow` — A Boolean value that specifies whether to open the destination PDF document in a new window.

8. Set the action to the annotation with the [`SetAnnotationAction` method]. It requires the annotation and the action IDs.

9. Save the PDF document to a file with the [`SaveToFile` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SaveToFile.html).

The return value of the `NewActionLaunch` method is the action’s ID. It’s required to assign the trigger element of the newly created action.

To create an action that navigates to the third page of the PDF document, use the following code:

### C#

```csharp

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Set the origin of the coordinate system.
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
// Set the measurement unit to centimeters.
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
// Select the second PDF page.
gdpicturePDF.SelectPage(2);
// Create a new action.
int actionID = gdpicturePDF.NewActionLaunch("notepad.exe", "", "", PdfActionLaunchOperation.ActionLaunchOperationUndefined, true);

gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");

```

### VB.NET

```vb

Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Set the origin of the coordinate system.
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
    ' Set the measurement unit to centimeters.
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
    ' Select the second PDF page.
    gdpicturePDF.SelectPage(2)
    ' Create a new action.
    Dim actionID As Integer = gdpicturePDF.NewActionLaunch("notepad.exe", "", "", PdfActionLaunchOperation.ActionLaunchOperationUndefined, true)

    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
End Using

```

#### Used methods

- [`AddPushButtonFormField`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddPushButtonFormField.html)

- [`AddStandardFont`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddStandardFont.html)

- [`LoadFromFile`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~LoadFromFile.html)

- [`NewActionLaunch`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~NewActionLaunch.html)

- [`SaveToFile`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SaveToFile.html)

- [`SelectPage`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SelectPage.html)

- [`SetFormFieldAction`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetFormFieldAction.html)

- [`SetMeasurementUnit`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetMeasurementUnit.html)

- [`SetOrigin`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetOrigin.html)

#### Related topics

- [Load a file](/guides/dotnet/load-a-file.md)

- [Save a file](/guides/dotnet/save-a-file.md)

## Opening a link to a website

To create an action that opens a website, use the following steps:

1. Create a `GdPicturePDF` object.

2. Load the PDF file with the [`LoadFromFile` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~LoadFromFile.html).

3. Set the origin of the coordinate system with the [`SetOrigin` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetOrigin.html). This method requires the [`PDFOrigin` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.PdfOrigin.html).

4. Set the measurement unit with the [`SetMeasurementUnit` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetMeasurementUnit.html) to specify the form field’s dimensions and position. This method uses the [`PdfMeasurementUnit` enumeration].

5. Set the PDF page where you want to place the form field with the [`SelectPage` method].

6. Add any type of annotation.

7. Create a new action with the [`NewActionLaunch` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~NewActionLaunch.html). It uses the following parameters:
   - `URI` — Website address represented as a uniform resource identifier and encoded in 7-bit ASCII.
   - `IsMap` — Specifies whether to track the mouse position when the URI is resolved. This behavior works only for actions triggered from a PDF annotation.

8. Set the action to the annotation with the [`SetAnnotationAction` method]. It requires the annotation and the action IDs.

9. Save the PDF document to a file with the [`SaveToFile` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SaveToFile.html).

The return value of the `NewActionURI` method is the action’s ID. It’s required to assign the trigger element of the newly created action.

To create an action that navigates to the third page of the PDF document, use the following code:

### C#

```csharp

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Set the origin of the coordinate system.
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
// Set the measurement unit to centimeters.
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
// Select the second PDF page.
gdpicturePDF.SelectPage(2);
// Create a new action.
int actionID = gdpicturePDF.NewActionURI(@"https:\\pspdfkit.com\", false);

gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");

```

### VB.NET

```vb

Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Set the origin of the coordinate system.
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
    ' Set the measurement unit to centimeters.
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
    ' Select the second PDF page.
    gdpicturePDF.SelectPage(2)
    ' Create a new action.
    Dim actionID As Integer = gdpicturePDF.NewActionURI(@"https:\\pspdfkit.com\", false)

    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
End Using

```

#### Used methods

- [`AddPushButtonFormField`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddPushButtonFormField.html)

- [`AddStandardFont`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddStandardFont.html)

- [`LoadFromFile`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~LoadFromFile.html)

- [`NewActionURI`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~NewActionURI.html)

- [`SaveToFile`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SaveToFile.html)

- [`SelectPage`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SelectPage.html)

- [`SetFormFieldAction`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetFormFieldAction.html)

- [`SetMeasurementUnit`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetMeasurementUnit.html)

- [`SetOrigin`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetOrigin.html)

#### Related topics

- [Load a file](/guides/dotnet/load-a-file.md)

- [Save a file](/guides/dotnet/save-a-file.md)

## Running JavaScript

To create an action that triggers JavaScript, use the following steps:

1. Create a `GdPicturePDF` object.

2. Load the PDF file with the [`LoadFromFile` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPicturePDF~LoadFromFile.html).

3. Set the origin of the coordinate system with the [`SetOrigin` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetOrigin.html). This method requires the [`PDFOrigin` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.PdfOrigin.html).

4. Set the measurement unit with the [`SetMeasurementUnit` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetMeasurementUnit.html) to specify the form field’s dimensions and position. This method uses the [`PdfMeasurementUnit` enumeration].

5. Set the PDF page where you want to place the form field with the [`SelectPage` method].

6. Add any type of annotation.

7. Create a new action with the [`NewActionJavaScript` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~NewActionJavaScript.html). It uses a string parameter as its parameter, which contains the JavaScript code.

8. Set the action to the annotation with the [`SetAnnotationAction` method]. It requires the annotation and the action IDs.

9. Save the PDF document to a file with the [`SaveToFile` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SaveToFile.html).

The return value of the `NewActionURI` method is the action’s ID. It’s required to assign the trigger element of the newly created action.

To create an action that navigates to the third page of the PDF document, use the following code:

### C#

```csharp

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Set the origin of the coordinate system.
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
// Set the measurement unit to centimeters.
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
// Select the second PDF page.
gdpicturePDF.SelectPage(2);
// Create a new action.
int actionID = gdpicturePDF.NewActionJavaScript("app.alert(\"Hello!\");");

gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");

```

### VB.NET

```vb

Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Set the origin of the coordinate system.
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
    ' Set the measurement unit to centimeters.
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
    ' Select the second PDF page.
    gdpicturePDF.SelectPage(2)
    ' Create a new action.
    Dim actionID As Integer = gdpicturePDF.NewActionJavaScript("app.alert(\"Hello!\");")

    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
End Using

```

#### Used methods

- [`AddPushButtonFormField`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddPushButtonFormField.html)

- [`AddStandardFont`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~AddStandardFont.html)

- [`LoadFromFile`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~LoadFromFile.html)

- [`NewActionJavaScript`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~NewActionJavaScript.html)

- [`SaveToFile`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SaveToFile.html)

- [`SelectPage`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SelectPage.html)

- [`SetFormFieldAction`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetFormFieldAction.html)

- [`SetMeasurementUnit`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetMeasurementUnit.html)

- [`SetOrigin`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~SetOrigin.html)

#### Related topics

- [Load a file](/guides/dotnet/load-a-file.md)

- [Save a file](/guides/dotnet/save-a-file.md)

## Getting the action ID

To get the ID of an action associated with an annotation, use the [`GetAnnotationActionID` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~GetAnnotationActionID.html). It requires the annotation ID as its parameter:

### C#

```csharp

using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");
// Set the origin of the coordinate system.
gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
// Set the measurement unit to centimeters.
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
// Select the second PDF page.
gdpicturePDF.SelectPage(2);
string fontResName = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica);
// Add a button form field.
int formID = gdpicturePDF.AddPushButtonFormField(2, 2, 5, 2, "pushButton", "Page 3", fontResName, 12, GdPicture14.Imaging.GdPictureColor.Blue);
// Create a new action.
gdpicturePDF.NewActionURI(@"https:\\pspdfkit.com\", false);
// Save the action ID to a variable.
int actionID = gdpicturePDF.GetAnnotationActionID(formID);
// Set the action to the form field
gdpicturePDF.SetFormFieldAction(formID, actionID);
gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");

```

### VB.NET

```vb

Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    gdpicturePDF.LoadFromFile("C:\temp\source.pdf")
    ' Set the origin of the coordinate system.
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
    ' Set the measurement unit to centimeters.
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
    ' Select the second PDF page.
    gdpicturePDF.SelectPage(2)
    Dim fontResName As String = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica)
    ' Add a button form field.
    Dim formID As Integer = gdpicturePDF.AddPushButtonFormField(2, 2, 5, 2, "pushButton", "Page 3", fontResName, 12, GdPicture14.Imaging.GdPictureColor.Blue)
    ' Create a new action.
    gdpicturePDF.NewActionURI("https:\\pspdfkit.com\", False)
    ' Save the action ID to a variable.
    Dim actionID As Integer = gdpicturePDF.GetAnnotationActionID(formID)
    ' Set the action to the form field
    gdpicturePDF.SetFormFieldAction(formID, actionID)
    gdpicturePDF.SaveToFile("C:\temp\output.pdf")
End Using

```

## Getting the action properties

To get the action’s properties, use any of the following methods:

- [`GetActionType`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~GetActionType.html) — Returns a member of the [`PdfActionType` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.PdfActionType.html) that specifies the action type.

- [`GetActionPageDestination`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~GetActionPageDestination.html) — Returns all parameters of an action that navigates to a different page of the currently opened PDF document.

- [`GetActionRemotePageDestination`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~GetActionRemotePageDestination.html) — Returns all parameters of an action that navigates to a different page of a different PDF document.

- [`GetActionLaunchDestination`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~GetActionLaunchDestination.html) — Returns all parameters of an action that opens a new application.

- [`GetActionURI`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~GetActionURI.html) — Returns the URL of the destination website.

- [`GetActionJavaScript`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPicturePDF~GetActionJavaScript.html) — Returns the JavaScript code triggered by the action.
---

## Related pages

- [Custom annotations](/guides/dotnet/annotations/custom-annotations.md)
- [Annotate on images in C# .NET](/guides/dotnet/annotations/annotate-on-images.md)
- [Attach an image to an annotation in C#](/guides/dotnet/annotations/attach-an-image.md)
- [Attach a file to an annotation in C#](/guides/dotnet/annotations/attach-a-file.md)
- [Create an annotation in a PDF using C#](/guides/dotnet/annotations/create.md)
- [Edit PDF annotations in C#](/guides/dotnet/annotations/edit.md)
- [Export XMP annotation data in C# .NET](/guides/dotnet/annotations/export-xmp.md)
- [Export annotation data from PDFs in C# .NET](/guides/dotnet/annotations/export-pdf.md)
- [Flatten PDF annotations in C# .NET](/guides/dotnet/annotations/flatten.md)
- [Get PDF annotation properties in C# .NET](/guides/dotnet/annotations/get-properties.md)
- [Import XFDF annotation data to PDFs in C# .NET](/guides/dotnet/annotations/import-xfdf.md)
- [Remove PDF annotations in C# .NET](/guides/dotnet/annotations/remove.md)
- [PDF annotations in C#.NET](/guides/dotnet/annotations.md)
- [Import XMP annotation data to PDF or image in C#](/guides/dotnet/annotations/import-xmp.md)
- [Stamp a PDF document in C# .NET](/guides/dotnet/annotations/stamp-a-document.md)
- [XMP annotations in C# .NET](/guides/dotnet/annotations/xmp-annotations.md)

