Examples

Add Actions to a PDF

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. Use these actions to perform tasks in places such as outlines, links, buttons or in any Document, Page or Form Field Reader Events.

How to Add Goto Action to PDF in C#

The Goto Action is used to move or navigate to a particular page on the PDF document. The following steps and sample code illustrate adding a Goto Action to PDF document using DynamicPDF Core Suite.

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 instance.
  3. Create a Button object.
  4. Create a GoToAction object and set its parameters.
  5. Add the Button instance to the Page instance.
  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#

The Import Form Data Action is used to fill form fields by importing data from an FDF file. The following steps and sample code illustrate adding an Import Form Data Action to a PDF document using DynamicPDF Core Suite.

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 instance.
  3. Create a Button object.
  4. Create a ImportFormDataAction object and set its parameters.
  5. Add the Button instance to the Page object.
  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 a PDF in C#

The Reset Action resets all form field values to their default values. The following steps and sample code illustrate adding a Reset Action to a PDF document using DynamicPDF Core Suite.

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 instance.
  3. Create a ResetAction object.
  4. Create a Button object and set its parameters.
  5. Add the Button object to the Page object instance.
  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 data in form fields to a specified URL. The following steps and sample code illustrate adding a Submit Action to an PDF document using DynamicPDF Core Suite.

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 object.
  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 instance.
  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 a URL Action to a PDF in C#

The URL Action links a web URL destination within a PDF document. The following steps and sample code add a URL Action to a PDF document using DynamicPDF Core Suite.

Steps for Adding a URL Action to a PDF Document

  1. Create a Document object.
  2. Create a Page object and add it to the Document object instance.
  3. Create a UrlAction object and set its URL.
  4. Create a Link object and set its value to the text link that represents the URL.
  5. Add the Link object to the Page instance.
  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 a File Open Action to a PDF in C#

The File Open Action Action opens a file, provided a native application to open the specific file is already installed. The steps and sample code that follows illustrates adding a File Open Action to a PDF document using the DynamicPDF Core Suite.

Steps for Adding the File Open Action to a PDF Document

  1. Create a Document object.
  2. Create a Page object and add it to the Document instance.
  3. Create a Button object.
  4. Create a FileOpenAction object and set its parameters.
  5. Add the Button object to the Page instance.
  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" );

GitHub Project

An example project is available on GitHub. Clone or view the example project at GitHub. This specific example discussed on this page is the Examples/Actions.cs file.

Clone or View Example Project on GitHub

Getting Started

NuGet Package

The easiest way to install DynamicPDF Core Suite is through Visual Studio's Package Manager. The Core Suite package is also available on NuGet as the ceTe.DynamicPDF.CoreSuite.NET package. The Core Suite includes functionality for generating and merging PDFs and for creating rich PDF reports.

NuGet Package ID: ceTe.DynamicPDF.CoreSuite.NET

DynamicPDF CoreSuite Information

More information on DynamicPDF Core Suite is available online.

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 22 Years)
  • Free Evaluation
  • .NET Core Support (Most Products)
  • Flexible Licensing

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