Forum How do I...?

JS callback for async data load

jduren
We're potentially migrating from wkhtmltopdf over to princexml for PDF generation of some reports which include HIghcharts charts throughout them. The highcharts data is loaded asynchronously and a callback fired once all the charts have rendered their content.

I'm looking through the documentation but I can't find a clear-cut description of how to delay princexml generating the PDF until the ajax data has loaded? Is there a simple way to do this?

J
mikeday
Prince doesn't support asynchronous AJAX, so that's not going to be a problem. :)

More seriously, Highcharts may not work, as Prince finishes executing all scripts before commencing layout. (No reflow). This means that scripts that depend on layout information like element widths and heights will fail to work as expected.

If you specify an explicit width/height for generated charts so they don't have to guess then it might work, but I would recommend careful testing first. And try the Prince latest builds, which include more JavaScript DOM and SVG support than Prince 10.
jduren
We can potentially send the pre-rendered charts through the API to princexml. Essentially what's happening now is that the user is viewing the document online as an HTML layout within a component, they can then hit PDF to download the PDF version of document.

In our current set up, WKHTMLTOPDF is essentially loading that document all over again, whereas what we could do is fire the content of the rendered DOM element off to the princexml to render as it would have the svg content created by highcharts in it and we've already rendered it all once, no reason to render it again.

Will try that and see how it goes.
mikeday
That sounds like a great approach.