From bdc0b0562992d9c0d29bc5db139cf724e816c9ab Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Mon, 2 Mar 2020 23:41:07 +0100 Subject: [PATCH] Updated Third party viewer usage (markdown) --- Third-party-viewer-usage.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Third-party-viewer-usage.md b/Third-party-viewer-usage.md index 3461de5..3fc0336 100644 --- a/Third-party-viewer-usage.md +++ b/Third-party-viewer-usage.md @@ -12,4 +12,22 @@ document.addEventListener("webviewerloaded", function() { ``` ### Event bus -The viewer components can dispatch events on an event bus to which other components can listen and act upon. PDF.js dispatches common events on the event bus that the user provides. For custom deployments it is required to provide a manually made event bus instance since pull request [#11631](https://github.com/mozilla/pdf.js/pull/11631). This prevents having to use DOM events for this purpose, making the viewer more stand-alone. Event bus instances have an `on` method to start listening for an event, an `off` method to stop listening for an event and a `dispatch` method to send an event through the event bus for other viewer components. \ No newline at end of file +The viewer components can dispatch events on an event bus to which other components can listen and act upon. PDF.js dispatches common events on the event bus that the user provides. For custom deployments it is required to provide a manually made event bus instance since pull request [#11631](https://github.com/mozilla/pdf.js/pull/11631). This prevents having to use DOM events for this purpose, making the viewer more stand-alone. Event bus instances have an `on` method to start listening for an event, an `off` method to stop listening for an event and a `dispatch` method to send an event through the event bus for other viewer components. + +For example, to perform an action when the page is initialized, you can use the following code: + +```javascript +// Create the event bus instance for the viewer application. +const eventBus = new pdfjsViewer.EventBus(); + +// Pass the event bus instance to the PDF viewer. +const pdfViewer = new pdfjsViewer.PDFViewer({ + ... + eventBus: eventBus, +}); + +// Listen for `pagesinit` events on the event bus. +eventBus.on("pagesinit", function() { + // Handle the `pagesinit` event here. +}); +``` \ No newline at end of file