This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/dotnet/annotations/pdf-actions-support.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. PDF form field actions in C# | Nutrient .NET SDK
Download sample

PDF actions enable you to perform the following tasks:

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:
  3. Set the action to the annotation.
  4. Save the PDF document to a file.

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.
  3. Set the origin of the coordinate system with the SetOrigin method. This method requires the PDFOrigin enumeration.
  4. Set the measurement unit with the SetMeasurementUnit method to specify the annotation’s dimensions and position. This method uses the PdfMeasurementUnit enumeration.
  5. Set the PDF page where you want to place the annotation with the SelectPage method.
  6. Add any type of annotation.
  7. Create a new action with the NewActionGoTo method. It uses the following parameters:
    • DestinationType — A member of the PdfDestinationType enumeration 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.
    • RetainTop — Optional: To keep the top 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.

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:

Register the SDK license before running SDK operations. For setup details, refer to the getting started with .NET SDK guide.

using GdPicture14;
LicenseManager license = new LicenseManager();
license.RegisterKEY("");
{
using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"input.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);
// Add a free text annotation.
int annotID = gdpicturePDF.AddFreeTextAnnotation(2, 2, 5, 2, true, "Action", "Action", "Open", "", 12, 0, 0, 200, 100, 100, 100, 1f);
// Set the action to the annotation.
gdpicturePDF.SetAnnotationAction(annotID, actionID);
gdpicturePDF.SaveToFile(@"output.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.
  3. Set the origin of the coordinate system with the SetOrigin method. This method requires the PDFOrigin enumeration.
  4. Set the measurement unit with the SetMeasurementUnit method to specify the annotation’s dimensions and position. This method uses the PdfMeasurementUnit enumeration.
  5. Set the PDF page where you want to place the annotation with the SelectPage method.
  6. Add any type of annotation.
  7. Create a new action with the NewActionGoToR method. It uses the following parameters:
    • DestinationType — A member of the PdfDestinationType enumeration 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.
    • RetainTop — Optional: To keep the top 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.

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:

{
using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"input.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);
// Add a free text annotation.
int annotID = gdpicturePDF.AddFreeTextAnnotation(2, 2, 5, 2, true, "Action", "Action", "Open", "", 12, 0, 0, 200, 100, 100, 100, 1f);
// Set the action to the annotation.
gdpicturePDF.SetAnnotationAction(annotID, actionID);
gdpicturePDF.SaveToFile(@"output.pdf");
}

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.
  3. Set the origin of the coordinate system with the SetOrigin method. This method requires the PDFOrigin enumeration.
  4. Set the measurement unit with the SetMeasurementUnit method to specify the annotation’s dimensions and position. This method uses the PdfMeasurementUnit enumeration.
  5. Set the PDF page where you want to place the annotation with the SelectPage method.
  6. Add any type of annotation.
  7. Create a new action with the NewActionLaunch method. 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. 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.

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 launches Notepad, use the following code:

{
using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"input.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);
// Add a free text annotation.
int annotID = gdpicturePDF.AddFreeTextAnnotation(2, 2, 5, 2, true, "Action", "Action", "Open", "", 12, 0, 0, 200, 100, 100, 100, 1f);
// Set the action to the annotation.
gdpicturePDF.SetAnnotationAction(annotID, actionID);
gdpicturePDF.SaveToFile(@"output.pdf");
}

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.
  3. Set the origin of the coordinate system with the SetOrigin method. This method requires the PDFOrigin enumeration.
  4. Set the measurement unit with the SetMeasurementUnit method to specify the annotation’s dimensions and position. This method uses the PdfMeasurementUnit enumeration.
  5. Set the PDF page where you want to place the annotation with the SelectPage method.
  6. Add any type of annotation.
  7. Create a new action with the NewActionURI method. 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.

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 opens a website, use the following code:

{
using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"input.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://www.nutrient.io/", false);
// Add a free text annotation.
int annotID = gdpicturePDF.AddFreeTextAnnotation(2, 2, 5, 2, true, "Action", "Action", "Open", "", 12, 0, 0, 200, 100, 100, 100, 1f);
// Set the action to the annotation.
gdpicturePDF.SetAnnotationAction(annotID, actionID);
gdpicturePDF.SaveToFile(@"output.pdf");
}

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.
  3. Set the origin of the coordinate system with the SetOrigin method. This method requires the PDFOrigin enumeration.
  4. Set the measurement unit with the SetMeasurementUnit method to specify the annotation’s dimensions and position. This method uses the PdfMeasurementUnit enumeration.
  5. Set the PDF page where you want to place the annotation with the SelectPage method.
  6. Add any type of annotation.
  7. Create a new action with the NewActionJavaScript method. 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.

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

To create an action that runs JavaScript, use the following code:

{
using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"input.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!\");");
// Add a free text annotation.
int annotID = gdpicturePDF.AddFreeTextAnnotation(2, 2, 5, 2, true, "Action", "Action", "Open", "", 12, 0, 0, 200, 100, 100, 100, 1f);
// Set the action to the annotation.
gdpicturePDF.SetAnnotationAction(annotID, actionID);
gdpicturePDF.SaveToFile(@"output.pdf");
}

Getting the action ID

To get the ID of an action associated with an annotation, use the GetAnnotationActionID method. It requires the annotation ID as its parameter:

{
using GdPicturePDF gdpicturePDF = new GdPicturePDF();
gdpicturePDF.LoadFromFile(@"input.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);
// Add a free text annotation.
int annotID = gdpicturePDF.AddFreeTextAnnotation(2, 2, 5, 2, true, "Action", "Action", "Open", "", 12, 0, 0, 200, 100, 100, 100, 1f);
// Create a new action and set it to the annotation.
int newActionID = gdpicturePDF.NewActionURI("https://www.nutrient.io/", false);
gdpicturePDF.SetAnnotationAction(annotID, newActionID);
// Get the ID of the action associated with the annotation.
int actionID = gdpicturePDF.GetAnnotationActionID(annotID);
Console.WriteLine($"Action ID: {actionID}");
}

Getting the action properties

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