How to know if PDF.JS has finished rendering?

后端 未结 12 1154
情深已故
情深已故 2020-12-13 14:44

I am using PDF.JS to render pdf pages into different canvas elements. my requirement is to capture the output of the canvas and to display it as an image. Is there some even

12条回答
  •  误落风尘
    2020-12-13 14:56

    Depending on which components (and version) of PDF.js you are making use of, you can also use the EventBus.

    If you are using the simplest implementation of PDF.js then this might not be available, but if you are using their SimpleViewer or PageViewer examples, try this:

            eventBus.on("pagesloaded", function() {
                console.log('pagesloaded');
                // your code here
            });
    
    

    eventBus should already be defined, if not, you can set it up using:

    var eventBus = new pdfjsViewer.EventBus();
    

    Again, this depends on the level of complexity in your PDF Viewer. Turns out there are many different layers within PDF.js.

    To listen for every page load, use the eventBus event 'pagerendered'

提交回复
热议问题