Updated Third party viewer usage (markdown)

Tim van der Meij 2020-03-02 23:41:07 +01:00
parent ba39566079
commit bdc0b05629

@ -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.
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.
});
```