When working with WebViewer, knowing when to run your code is just as important as knowing what code to write. WebViewer provides a lifecycle of events that allow you to react as the viewer initializes, documents load, annotations become available, and users interact with content.
The first event you’ll encounter is when the WebViewer() promise resolves.
WebViewer(options, viewerElement).then(instance => {// Setup code});
This is the ideal place to:
Think of this as your application’s initialization phase.
Once a document is loaded into memory, the documentLoaded event fires.
documentViewer.addEventListener('documentLoaded', () => {// Work with the document});
Use this event for:
As pages render, WebViewer triggers the pageComplete event.
documentViewer.addEventListener('pageComplete', pageNumber => {// Page fully rendered});
This is useful when you need access to rendered page content, canvases, or custom overlays.
Annotations are loaded asynchronously. When all annotations are available, annotationsLoaded fires.
documentViewer.addEventListener('annotationsLoaded', () => {// All annotations available});
Use this event when exporting, processing, or displaying annotation-related data.
After the document is fully loaded, WebViewer continuously emits events based on user activity:
pageNumberUpdatedzoomUpdatedsearchResultsChangedtoolbarGroupChangedselectedThumbnailChangedannotationChangedannotationSelectedannotationDeselectedtextSelectedselectionCompleteThese events allow you to build custom workflows, analytics, autosave functionality, and interactive experiences.
A common workflow is loading annotations from a server and automatically saving user changes.
This pattern is used in document review, collaboration, and approval workflows.
WebViewer().then().documentLoaded for document-related operations.annotationsLoaded when working with annotations.annotationChanged to detect user edits.documentLoaded, as it fires every time a new document is opened.By understanding the lifecycle and choosing the correct event for each task, you can build reliable and performant WebViewer applications.