Skip to main content

Reader Events

Version: 12.0

Add Reader Events to PDFs

Add interactivity to a PDF by adding reader events to a document, page, or form fields using DynamicPDF Core Suite for .NET. The following C# examples show you how.

How to Add Document Reader Event to PDF in C#​

The following steps and C# sample code illustrate adding a reader event to a document using DynamicPDF Core Suite for .NET so that events are triggered at the document level.

Steps for Adding Document Reader Event to PDF Document​

  1. Create a Document object.
  2. Create a JavaScriptAction object and provide the script to be executed.
  3. Assign the action to the Document instance's ReaderEvents property's DocumentReaderEvents.WillSave event.
  4. Save the PDF document.

Sample Code - C#​

Document document = new Document();
JavaScriptAction action = new JavaScriptAction("app.alert(\"Hello your text was Saved!\")");
document.ReaderEvents.WillSave = action;
document.Draw( "output.pdf" );

How to Add Page Reader Event to PDF in C#​

The following steps and C# sample code illustrate adding a reader event to a page using DynamicPDF Core Suite for .NET.

Steps for Adding Page Reader Event to PDF Document​

  1. Create a Document object.
  2. Create a Page object and add it to the Document instance.
  3. Create a JavaScriptAction object and provide the script to be executed.
  4. Assign the action to the Page instance's ReaderEvents property's PageReaderEvents.Open event.
  5. Save the PDF document.

Sample Code - C#​

Document document = new Document();
Page page = new Page();
document.Pages.Add( page );
JavaScriptAction action = new JavaScriptAction("app.alert(\"Welcome !\")");
page.ReaderEvents.Open = action;
document.Draw( "output.pdf" );

How to Add Form Field Reader Event to PDF in C#​

The following steps and C# sample code illustrate adding a form field event to a PDF document using DynamicPDF Core Suite for .NET.

Steps for Adding Form Field Reader Event to a PDF Document​

  1. Create a Document object.
  2. Create a Page object and add it to the Document.
  3. Create a TextField object.
  4. Create a JavaScriptAction object and provide the script to be executed.
  5. Assign the action to the TextField instance's ReaderEvents property's AnnotationReaderEvents.OnFocus event.
  6. Save the PDF document.

Sample Code - C#​

Document document = new Document();
Page page = new Page();
document.Pages.Add( page );
TextField textField = new TextField("Text1", 0, 0, 100, 15);
JavaScriptAction action = new JavaScriptAction("app.alert(\"Welcome !\")");
textField.ReaderEvents.OnFocus = action;
page.Elements.Add(textField);
document.Draw("output.pdf" );

GitHub Project​

Examples are provided in C# and VB.NET. Clone or view the example project at GitHub. This example code is contained in the following files.

View source on GitHub: Core Suite .NET Core Examples

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.

Get ceTe.DynamicPDF.CoreSuite.NET from NuGet

DynamicPDF Core Suite for .NET 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 Reader Events​

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.