Forum How do I...?

Manual trigger when page is fully loaded

evjmcmillan

I wasnt able to find this in the documentation, or searching forums, apologies if I missed something obvious:

How do I manually trigger when a page is done loading and ready for the pdf to be created?

Our current pdf provider has a javascript function that we call when ready similar to:
pdfProvider.startPdfConversion();

Is there a similar method call for Prince?
mikeday
Prince will automatically create the PDF when the page has finished loading; why does it need to be manually triggered?
evjmcmillan

Need to be able to manually trigger to ensure all async resources, ajax requests are finished, and all charts have finished drawing and adjusting as needed.

Or is Prince meant for static html resources to pdf, and not javascript web apps?
mikeday
Prince runs JavaScript but doesn't support asynchronous AJAX requests or document reflow, eg. all JavaScript finishes running before layout begins.
hallvord
Hi, given that Prince by design should handle this "automatically" (an approach that has pros and cons!) it would be interesting to know exactly what doesn't work for you. Perhaps you use a chart library that calls setTimeout() excessively for animation before it finishes the rendering, or something similar? Just an example, I tried to write a "compat shim" that would make Highcharts work in Prince and one of the things I did was to disable animations through a rather ugly hack.. https://github.com/yeslogic/prince-scripts/blob/master/compatibility/Highcharts/compat.js

Announcement: repos for tests/utils

evjmcmillan

Thanks for the replies, looks like Prince will not be an alternative for us without an option to manually trigger. There is more than just Highcharts, resources and api calls made asynchronously, layout runs, etc.