Nutrient Web SDK

ReferenceEvents

Namespace Events

The Events namespace contains all the event types that can be used with the addEventListener() method. These events provide a comprehensive way to monitor and respond to changes within the PDF viewer.

Each event has a corresponding event listener type that defines the expected function signature. These types ensure type safety when registering event listeners and provide clear documentation of the parameters each event listener receives.

Many events follow a lifecycle pattern:

  • Will events: Fired before an action occurs
  • Change events: Fired when the state changes
  • Did events: Fired after an action completes

For example, with annotations:

  • annotations.willSave → annotations.change → annotations.didSave
Namespace

Example

// Listen for view state changes
instance.addEventListener("viewState.change", (viewState, previousViewState) => {
console.log("View state changed:", viewState.toJS());
});

// Listen for annotation creation
instance.addEventListener("annotations.create", (annotations) => {
console.log("New annotations created:", annotations.toJS());
});

// Listen for page navigation
instance.addEventListener("viewState.currentPageIndex.change", (pageIndex) => {
console.log("Current page changed to:", pageIndex);
});

Interfaces

Type Aliases