New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Callback for when PDF is finished rendering? #5601
Comments
We have 'pagerendered' event or render() returns promise. The generic viewer never renders all pages, so this will not be fixable for the viewer, unless we introduce a mode for the PDFViewer object when it renders all pages. |
Ok, so a 'pagerendered' event is fired from which object? @yurydelendik |
See https://github.com/mozilla/pdf.js/blob/master/web/pdf_viewer.js#L225 and example of usage at https://github.com/mozilla/pdf.js/blob/master/web/viewer.js#L1733 Please notice that we don't have API for viewer. Only API we released is for core and canvas rendering (see src/display/api.js). |
@yurydelendik I am using this with canvas, in-browser. I'm kind of confused about where else PDF JS is even relevant. That confused me right away, but anyway, it looks like you have what I'm looking for. Thanks so much! |
Closing as resolved. |
I'm having trouble catching this event. I listen (Jquery) for the
and render the PDF on canvas:
Triggering the event myself works successfully, so my listener is set up properly, and is attached long before Perhaps I misunderstood the event's trigger. When exactly should the |
If you are not using the generic viewer, the event will not be triggered. Sorry, I don't understood what you are asking. See https://github.com/mozilla/pdf.js/blob/master/examples/learning/prevnext.html#L76 to see how to wait for rendering to finish. jQuery will be less useful here, try to learn how to use Promises. |
@yurydelendik I understand now, thank you so much for your time! |
Using the
|
Using your snippet above you'd simply do: page.render(renderContext).then(function() {
console.log("FINISHED RENDERING!");
}, function() {
console.log("ERROR");
}); |
@brendandahl thanks ) |
Thank you @lucdetellis ! I have been trying to have a button external to the viewer trigger the print functionality, but it would never work due to the error given. Using your solution inside of a function allowed me to trigger that function from the parent frame and then window.focus() and window.print() when finished rendering, and BAM, issue resolved.. Was looking all over for a solution on this :) |
Is never called for me... I'm calling it like so (at the end
Please forgive my javascript ignorance, I'm an Android developer trying to get js callbacks for when the PDF has finished rendering because I'm running into some Android specific issues... Any help would be greatly appreciated. Updated: |
Using the viewer provided with pdf.js,
|
@turquoise-turtle did you attached to event Listener to the main document or to the iframe where you have the viewer?
i'm doing this and it doesn't seem to work |
set "eventBusDispatchToDOM": true in viewer.js why isn't anyone telling this! |
It seems the default was changed to not dispatch events to DOM in around August to September, looking at #10019 |
please see: #10718 (comment) |
I need to render a gradient to cover the bottom half of the rendered PDF. I'm working for a newspaper and we're doing an app that shows the paper with a teaser before subscribing.
The problem is, the gradient needs to be painted on top of the PDF, so it has to wait until the PDF is finished rendering. In fact, on mobile browsers attempting the gradient rendering before the PDF is finished results in extremely wild behavior (the canvas re-renders and blinks every time the page scrolls even a bit) resulting in constant re-paints and the content will render upside down sometimes.
So quite simply, I need to run a callback when the PDF has finished rendering.
Can you guys support callbacks? Or send out an event when the rendering is done?
The text was updated successfully, but these errors were encountered: