Does PDF.js raise an event as I browse between pages?
Basically I want to update the URL and add to pushstate when I browse between pages in a PDF.js document.
Does PDF.js raise an event as I browse between pages, and if so what is the event called?
Thanks
PDF. js leverages Asynchronous JavaScript and XML (AJAX) to download the PDF file from a web server and parse its contents. Once prepared, content is then rendered onto an HTML5 <canvas> element using canvas drawing commands.
What Browsers does PDF. js Support. PDF. js is used within Mozilla Firefox today as the built-in PDF viewer, and it works well within a website when viewed using the latest versions of Chrome and Firefox, whether through the pre-built PDF.
js is a JavaScript library that renders Portable Document Format (PDF) files using the web standards-compliant HTML5 Canvas. The project is led by the Mozilla Corporation after Andreas Gal launched it (initially as an experiment) in 2011.
Yeah, there is an event named pagechange.
You can use it like that:
document.addEventListener('pagechange', function(e) {
if (e.pageNumber !== e.previousPageNumber) {
console.log('page changed from ' + e.previousPageNumber + ' to ' + e.pageNumber);
}
});
Open the viewer and drop the code above into the console, and see what happens!
Now in v2.1.233 of pdf.js, the event is pagechanging.
The following code worked for me -
window.PDFViewerApplication.eventBus.on('pagechanging', function pagechange(evt) {
console.log(evt)
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With