PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
There are two kinds of events: Core events, fired by documentViewer, annotationManager and other Core objects, and UI events, fired by instance.UI.
Core objects have addEventListener(name, handler, options?) and removeEventListener(name, handler):
const { documentViewer, annotationManager } = instance.Core;
documentViewer.addEventListener('pageNumberUpdated', (pageNumber) => console.log(pageNumber));
annotationManager.addEventListener('annotationChanged', (annotations, action) => console.log(action));documentViewer events | Event | Arguments | Fires when |
|---|---|---|
documentLoaded | — | The document finishes loading. |
documentUnloaded | — | The document is closed. |
annotationsLoaded | — | The annotations of the document are loaded. |
pageNumberUpdated | pageNumber | The current page changes. |
pagesUpdated | changes | Pages are added, removed, moved or rotated. |
zoomUpdated | zoom | The zoom level changes. |
rotationUpdated | rotation | The rotation changes. |
fitModeUpdated | fitMode | The fit mode changes. |
toolModeUpdated | newTool, oldTool | The active tool changes. |
textSelected | quads, text, pageNumber | Text is selected. |
searchResultsChanged | results | The search results change. |
finishedRendering | — | Rendering of the visible pages finishes. |
click | event | The document area is clicked. |
annotationManager events | Event | Arguments | Fires when |
|---|---|---|
annotationChanged | annotations, action, info | Annotations are added / modified / deleted (action is 'add', 'modify' or 'delete'). |
annotationSelected | annotations, action | Annotations are selected ('selected') or deselected ('deselected'). |
annotationDeselected | annotations | Annotations are deselected. |
History managers fire historyChanged (documentViewer.getAnnotationHistoryManager()) and undoRedoStatusChanged (documentViewer.getContentEditHistoryManager()).
instance.UI.addEventListener(name, handler, options?) and removeEventListener(name, handler) work with the names in instance.UI.Events:
| Event | Arguments | Fires when |
|---|---|---|
VIEWER_LOADED | — | The UI is mounted. Listeners added later are still called once. |
LOAD_ERROR | error | The UI or a document fails to load. |
VISIBILITY_CHANGED | dataElement, isVisible | An element is opened or closed. |
TOOLBAR_GROUP_CHANGED | toolbarGroup | The active toolbar group changes. |
THEME_CHANGED | theme | The theme changes. |
LANGUAGE_CHANGED | previousLanguage, newLanguage | The language changes. |
PANEL_RESIZED | dataElement, width | A panel width changes. |
FULLSCREEN_MODE_TOGGLED | isFullscreen | Full screen mode changes. |
FILE_DOWNLOADED | — | The document is downloaded. |
MODULAR_UI_IMPORTED | — | importModularComponents finishes. |
ACTIVE_DOCUMENT_VIEWER_CHANGED | newKey, oldKey | The active document viewer changes. |
PERMISSION_DENIED | { permission, action, documentViewerKey } | An action is not allowed by the document permissions. |
PERMISSION_VERIFIED | { documentViewerKey } | The permission password is verified. |
TRUSTED_CERTIFICATE_ADDED | { fieldName, certificate } | The user trusts a signer certificate in the certificate viewer. certificate is a copy of the DER bytes. Not fired by UI.VerificationOptions.addTrustedCertificates. The trust list is kept in memory only: save the certificate and pass it to addTrustedCertificates next time to trust it again. |
When an instance is created, the UI binds its handlers to the Core events of each document viewer (event-listeners/). The handlers update the stores — for example documentLoaded updates the page count and the outline, annotationSelected updates the selection, toolModeUpdated updates the active tool button. All bindings are removed when the instance is disposed.
Lifecycle note: remove the listeners you add with
removeEventListenerwhen you no longer need them, or pass{ once: true }for a listener that runs once.
instance.Core.documentViewer.addEventListener('documentLoaded', () => {
console.log('Document loaded');
});const handler = (annotations, action) => {
console.log('annotations', action, annotations);
};
instance.Core.annotationManager.addEventListener('annotationChanged', handler);
// later
instance.Core.annotationManager.removeEventListener('annotationChanged', handler);instance.Core.documentViewer.addEventListener('toolModeUpdated', (newTool) => {
console.log('Active tool:', newTool.name);
});const { UI } = instance;
UI.addEventListener(UI.Events.THEME_CHANGED, (theme) => console.log('theme', theme));
UI.addEventListener(UI.Events.TOOLBAR_GROUP_CHANGED, (group) => console.log('group', group));ComPDFKitViewer() resolves with instance when the UI is mounted, so code in .then() can use instance directly. Inside a config script (the config option), wait for UI.Events.VIEWER_LOADED:
instance.UI.addEventListener(instance.UI.Events.VIEWER_LOADED, () => {
console.log('Viewer Loaded');
});