Skip to main content

Events

Version: 12.0

Events

The DynamicPDF Core Suite for .Net supports document, page, and form reader events when an end-user uses a PDF reader like Adobe Acrobat.

info

See the Actions topic for more information on the actions that can be performed after triggered by an event.

ReaderEvents​

The Document, Page, and FormElement classes all have a ReaderEvents property that allows adding an Action to the specified event. The FormElement class's ReaderEvents expects an AnnotationReaderEvents. The Document class's ReaderEvents expects a DocumentReaderEvents while the Page class's expects a PageReaderEvents. The following lists the available events for each type of reader event.

ReaderEventsEvents
PageReaderEventsOpen, Close
DocumentReaderEventsDidPrint, DidSave, WillClose, WillPrint, WillSave
AnnotationReaderEventsMouseDown, MouseEnter, MouseExit, MouseUp, OnBlur, OnFocus

Page Reader Events (PageReaderEvents)​

The following events can be triggered when navigating to a PDF page.

  • Open - This event will be fired when opening a specific page.
  • Close - This event will be fired when closing a specific page.

The following example triggers a JavaScript alert window when a user navigates to a page and then a second alert window when a user then leaves that page.

Document document = new Document();
document.Pages.Add(new Page(PageSize.Letter));
document.Pages.Add(new Page(PageSize.Letter));
Page page = document.Pages[1];
JavaScriptAction action = new JavaScriptAction("app.alert(\"Welcome !!\")");
page.ReaderEvents.Open = action;

JavaScriptAction action2 = new JavaScriptAction("app.alert(\"Goodbye !!\")");
page.ReaderEvents.Close = action2;
document.Pages.Add(new Page(PageSize.Letter));
document.Draw(outputPath);
Dim document As New Document()
document.Pages.Add(New Page(PageSize.Letter))
document.Pages.Add(New Page(PageSize.Letter))
Dim page As Page = document.Pages(1)
Dim action As New JavaScriptAction("app.alert(""Welcome !!"")")
page.ReaderEvents.Open = action

Dim action2 As New JavaScriptAction("app.alert(""Goodbye !!"")")
page.ReaderEvents.Close = action2
document.Pages.Add(New Page(PageSize.Letter))
document.Draw(outputPath)

[EventsExample.cs](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-csharp-examples/Examples/EventsExample.cs){#gitlink-id target=_blank}


[EventsExample.vb](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-vbnet-examples/Examples/EventsExample.vb){#gitlink-id target=_blank}

^^^

Figure 1. A document with page reader events.

^^^

Document Reader Events (DocumentReaderEvents)​

The following events can be triggered at the document level.

  • WillSave - This event will be fired when saving a document.
  • DidSave - This event will be fired after saving a document.
  • WillClose - This event will be fired while closing a document.
  • WillPrint - This event will be fired when printing a document.
  • DidPrint - This event will be fired after printing a document.

The example below demonstrates how to trigger a JavaScript alert window when saving a PDF.

Document document = new Document();
JavaScriptAction action = new JavaScriptAction("app.alert(\"Hello your text Saved!!\")");
document.ReaderEvents.WillSave = action;
Dim document As Document = New Document()
Dim action As JavaScriptAction = New JavaScriptAction("app.alert('Hello your text Saved!!')")
document.ReaderEvents.WillSave = action

[EventsExample.cs](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-csharp-examples/Examples/EventsExample.cs){#gitlink-id target=_blank}


[EventsExample.vb](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-vbnet-examples/Examples/EventsExample.vb){#gitlink-id target=_blank}

Form Field Reader Events (AnnotationReaderEvents)​

The following events can be triggered for each form field.

  • MouseUp- This event is fired when the mouse button is released after a click.
  • MouseDown - This event is fired when the mouse button is clicked and not released.
  • MouseEnter - This event is fired when the mouse pointer enters the field.
  • MouseExit - This event is fired when the pointer exits the form field.
  • OnBlur - This event is fired when the form field loses focus.
  • OnFocus - This event is fired when the form field receives focus, either through a mouse action or by tabbing.

The example below demonstrates how to trigger a JavaScript alert window when a text field receives focus.

TextField textField = new TextField("Text1", 0, 0, 100, 15);
JavaScriptAction action = new JavaScriptAction("app.alert(\"Welcome !!\")");
textField.ReaderEvents.OnFocus = action;
Dim textField As TextField = New TextField("Text1", 0, 0, 100, 15)
Dim action As JavaScriptAction = New JavaScriptAction("app.alert('Welcome !!')")
textField.ReaderEvents.OnFocus = action

[EventsExample.cs](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-csharp-examples/Examples/EventsExample.cs){#gitlink-id target=_blank}


[EventsExample.vb](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-vbnet-examples/Examples/EventsExample.vb){#gitlink-id target=_blank}