Examples

Adding Actions to PDF

Add actions to a PDF document to perform tasks in places such as outlines, links, buttons, or in any document, page, or form field. The C# examples below illustrate that adding interactivity to your end user's PDFs is a breeze when using DynamicPDF Core Suite for .NET.

How to Add GotoAction to PDF

Use the GoToAction to navigate to a particular page on a PDF document. The following steps and C# sample code illustrates the action by creating two pages and adding an action that navigates between the two pages.


Steps for Adding GotoAction to a PDF Document


  1. Create a Document object.
  2. Create two Page objects and add them to the Document instance.
  3. Create a Button object.
  4. Create a GoToAction object and set its parameters.
  5. Set the button's ReaderEvents.Mouseup event to the action.
  6. Add the Button instance to the Page instance.
  7. Add the Draw method to output the PDF document.

Sample Code - C#


public static void GoToAction()
{
    Document document = new Document();
    Page page1 = new Page();
    document.Pages.Add(page1);
    Page page2 = new Page();
    page2.Elements.Add(new Label("Page 2", 0, 0, 100, 15));
    document.Pages.Add(page2);
    Button button = new Button("btn", 50, 150, 100, 30);
    button.Label = "Click Here";
    GoToAction action = new GoToAction(2, PageZoom.FitWidth);
    button.ReaderEvents.MouseUp = action;
    page1.Elements.Add(button);
    document.Draw("output.pdf");
}

How to Add ImportFormDataAction to PDF

The ImportFormDataAction fills a form's fields by importing data from a Forms Data Format (FDF) file. The following steps and C# sample code illustrate adding an ImportFormDataAction to a PDF document.


Steps for Adding ImportFormDataAction


  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 by specifying the path to the FDF file in the constructor.
  5. Set the button's ReaderEvents.Mouseup event to the action.
  6. Add the Button instance to the Page object.
  7. Add the Draw method to output the PDF document.

Note: Importing form data expects the form's data to be in Forms Data Format (FDF).


Sample Code - C#


public static void FormFillingFdfDataDocument()
{
    Document document = new Document();
    Page page = new Page();
    document.Pages.Add(page);
    Button button = new Button("btn", 50, 250, 100, 30);
    button.Label = "Fill Form";
    page.Elements.Add(button);
    ImportFormDataAction action = new ImportFormDataAction("simple-form-fill_data.fdf");
    button.ReaderEvents.MouseUp = action;
    document.Draw("formfilling-output.pdf");
}

How to Add ResetAction to PDF

The ResetAction resets all form field values to their default values. The following steps and C# sample code illustrate resetting a form.


Steps for Adding ResetAction 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. Set the button's ReaderEvents.MouseEnter event to the action.
  6. Add the Button object to the Page object instance.
  7. Add the Draw method to output the PDF document.

Sample Code - C#


public static void ResetAction()
{
    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("ResetAction.pdf");
}

How to Add SubmitAction to PDF

The SubmitAction sends data in form fields to a specified URL. The following steps and C# sample code illustrates this action.


Steps for Adding SubmitAction 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 and response type as FormExportFormat.HtmlPost.
  4. Create a Button object and set its parameters.
  5. Assign the action to SubmitAction object.
  6. Add the Button object to the Page instance.
  7. Add the Draw method to output the PDF document.

Sample Code - C#


public static void SubmitAction()
{
    Document document = new Document();
    Page page = new Page();
    document.Pages.Add(page);
    SubmitAction submitAction = new SubmitAction("http://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 URLAction to PDF

The URLAction links a web URL destination within a PDF document. The following steps and C# sample code add a URLAction to a PDF document using DynamicPDF Core Suite for .NET.


Steps for Adding a URLAction 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. Add the Draw method to output the PDF document.

Sample Code - C#


public static void UrlAction()
{
    Document document = new Document();
    Page page = new Page();
    document.Pages.Add(page);
    UrlAction action = new UrlAction("http://www.dynamicpdf.com");
    Link link = new Link(50, 50, Font.Helvetica.GetTextWidth("My Domain", 18), 20, action);  
    Button button = new Button("btn", 50, 100, 100, 50);
    button.Label = "Click";
    button.Action = action;
    page.Elements.Add(link);
    page.Elements.Add(button);
    document.Draw("output.pdf");
}

How to Add FileOpenAction to PDF

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


Steps for Adding the FileOpenAction 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 in its constructor specify the file to open and the launch mode (``FileLaunchMode.NewWindow`)
  5. Add the Button object to the Page instance.
  6. Add the Draw method to output the PDF document.

Sample Code - C#


public static void FileOpenAction()
{
    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("DocumentA.pdf", FileLaunchMode.NewWindow);
    button.ReaderEvents.MouseUp = action;
    age.Elements.Add(button);
    document.Draw("output.pdf");
}

GitHub Project

An example project is available on GitHub (examples.dynamicpdf-core-suite-dotnet-core). Examples are provided in C# and VB.NET. Clone or view the example project at GitHub. This specific example discussed on this page are all contained in following classes on GitHub.


Clone or View Example Project on GitHub

Getting Started

Get started easily by installing DynamicPDF Core Suite for .NET through NuGet or manually. Then, refer to the documentation for more information on using and purchasing the product.


NuGet Package


The easiest way to install DynamicPDF Core Suite is by obtaining the NuGet package using Visual Studio's Package Manager. You can also obtain the NuGet package by downloading it directly. Refer to the installation documentation for more information.

NuGet Package ID: ceTe.DynamicPDF.CoreSuite.NET

DynamicPDF Core Suite Information


DynamicPDF Core Suite for .NET combines creating, merging, and visual report creation into one powerful product for creating PDF documents. It is ideal for anyone who needs to generate PDF documents or reports or work with existing PDFs in their applications. With a free Evaluation Edition to try and with flexible and royalty-free licensing options, why not start using DynamicPDF Core Suite for .NET today!



More Information on Actions



Also See


Available on Other Platforms

DynamicPDF Core Suite is also available for the Java and COM/ActiveX platforms. 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!