Examples

Add Actions to PDF (.NET Core/Framework)

You can add different actions like Goto Action, Import Form Data Action, Reset Action, Submit Action, URL Action and File Open Action to PDF documents. These actions can be used to perform tasks in many places such as in outlines, links, buttons or in any Document, Page or Form Field Reader Events.

How to add Goto Action to PDF in C#

Goto Action is used to move or navigate to a particular page on the PDF document. Below are the steps and sample code to add a Goto Action to PDF document using the Generator product.

Steps for Adding Goto Action to a PDF Document

  1. Create a Document object.
  2. Create a Page object and add it to the Document.
  3. Create a Button object.
  4. Create a GoToAction object and set the parameters.
  5. Add the Button to the Page.
  6. Save the PDF document.

Sample Code - C#

Document document = new Document();
Page page = new Page();
document.Pages.Add( page );

Button button = new Button("btn", 50, 150, 100, 30);
button.Label = "Click Here";
GoToAction action = new GoToAction(2, PageZoom.FitWidth);
button.ReaderEvents.MouseUp = action;  

page.Elements.Add( button );	
document.Draw( "output.pdf" );

How to add Import Form Data Action to PDF in C#

Import Form Data Action can be used to fill the form fields by importing data from an FDF file. Below are the steps and sample code to add a Import Form Data Action to PDF document using the Generator product.

Steps for Adding Import Form Data Action to a PDF Document

  1. Create a Document object.
  2. Create a Page object and add it to the Document.
  3. Create a Button object.
  4. Create a ImportFormDataAction object and set the parameters.
  5. Add the Button to the Page.
  6. Save the PDF document.

Sample Code - C#

Document document = new Document();
Page page = new Page();
document.Pages.Add( page );

Button button = new Button("btn", 50, 150, 100, 30);
button.Label = "Click Here";
ImportFormDataAction action = new ImportFormDataAction(@"FdfFilePath");
button.ReaderEvents.MouseUp = action;  

page.Elements.Add( button );	
document.Draw( "output.pdf" );

How to add Reset Action to PDF in C#

The Reset Action is used to reset all form field values to their default values. Below are the steps and sample code to add a Reset Action to PDF document using the Generator product.

Steps for Adding Reset Action to a PDF Document

  1. Create a Document object.
  2. Create a Page object and add it to the Document.
  3. Create a ResetAction object.
  4. Create a Button object and set the parameters.
  5. Add the Button to the Page.
  6. Save the PDF document.

Sample Code - C#

Document document = new Document();
Page page = new Page();
document.Pages.Add( page );

ResetAction action = new ResetAction();
Button button = new Button("btn", 50, 300, 100, 50);
button.Label = "Reset";
button.ReaderEvents.MouseEnter = action;  

page.Elements.Add( button );	
document.Draw( "output.pdf" );

How to add Submit Action to PDF in C#

The Submit Action sends the data in form fields to a specified URL. Below are the steps and sample code to add a Submit Action to PDF document using the Generator product.

Steps for Adding Submit Action to a PDF Document

  1. Create a Document object.
  2. Create a Page object and add it to the Document.
  3. Create a SubmitAction object and set the URL.
  4. Create a Button object and set the parameters and assign the action to SubmitAction object.
  5. Add the Button object to the Page.
  6. Save the PDF document.

Sample Code - C#

Document document = new Document();
Page page = new Page();
document.Pages.Add( page );

SubmitAction submitAction = new SubmitAction("www.mydomain.com", FormExportFormat.HtmlPost);
Button button = new Button("btn", 50, 300, 100, 50);
button.Label = "Submit";
button.Action = submitAction;  

page.Elements.Add( button );	
document.Draw( "output.pdf" );

How to add URL Action to PDF in C#

The URL Action is used to link to a web URL destination from a PDF document. Below are the steps and sample code to add a URL Action to PDF document using the Generator product.

Steps for Adding URL Action to a PDF Document

  1. Create a Document object.
  2. Create a Page object and add it to the Document.
  3. Create a UrlAction object and set the URL.
  4. Create a Link object and set the text link that represents the URL.
  5. Add the Link object to the Page.
  6. Save the PDF document.

Sample Code - C#

Document document = new Document();
Page page = new Page();
document.Pages.Add( page );

UrlAction action = new UrlAction("http://www.mydomain.com");
Link link = new Link(50, 50, Font.Helvetica.GetTextWidth("My Domain", 18), 20, action);  

page.Elements.Add( link );	
document.Draw( "output.pdf" );

How to add File Open Action to PDF in C#

The File Open Action Action can be used to open a file, provided a native application to open that specific file is already installed. Below are the steps and sample code to add a File Open Action to PDF document using the Generator product.

Steps for Adding File Open Action to a PDF Document

  1. Create a Document object.
  2. Create a Page object and add it to the Document.
  3. Create a Button object.
  4. Create a FileOpenAction object and set the parameters.
  5. Add the Button to the Page.
  6. Save the PDF document.

Sample Code - C#

Document document = new Document();
Page page = new Page();
document.Pages.Add( page );

Button button = new Button("btn", 50, 150, 100, 30);
button.Label = "Click Here";
FileOpenAction action = new FileOpenAction(@"Path of the file to open", FileLaunchMode.NewWindow);
button.ReaderEvents.MouseUp = action;

page.Elements.Add( button );	
document.Draw( "output.pdf" );

Getting Started

NuGet Package

DynamicPDF Generator is available on NuGet and is part of the ceTe.DynamicPDF.CoreSuite.NET package. The Core Suite package includes Generator, Merger and ReportWriter.

NuGet Package ID: ceTe.DynamicPDF.CoreSuite.NET

GitHub Example Project

Clone or view the example project at GitHub. This example is is the Examples/Actions.cs file.

Clone or View Example Project on GitHub

DynamicPDF CoreSuite Information

More information on DynamicPDF CoreSuite can be found here:

Java and COM/ActiveX Platforms

The DynamicPDF Generator is also available for Java and COM/ActiveX. Refer to the respective product pages for more details.

Why Choose DynamicPDF?

  • Transparent Pricing
  • Lots of Features
  • Easy to Use
  • Great Support
  • Efficient Performance
  • Product Maturity (Over 18 Years)
  • Free Evaluation
  • .NET Core Support (Most Products)
  • Flexible Licensing

We’re Not The Only Ones That Think We’re Great!