How to await all chrome-PDF layout work before measuring elements?



  • I need to measure some elements. This works great with the following concept:

    1. In a script tag, iterate alle elements and collect element.getBoundingClientRect()
    2. stringify the measures and mashal them to the server side via console.log
    3. add measurement data to req.data
    4. start a second render where I now have access to the measurements

    Unfortunately, I'm having trouble with the timing. I'm currently measuring at window.onload. It seems as chrome-pdf applies the automatic page breaks after my measurements. I.e. the boundingboxes will sometimes relate to the position the element had before chrome-pdf added the automatic pagebreaks.

    Is there any way to await the complete layout?

    I tried with a simple setTimeout but jsReport does not await such timeouts on the client side.
    I also tried to set window.JSREPORT_READY_TO_START = false; and then set it to true after my timeout, but jsReport did not wait for this.



  • Update:
    I got window.JSREPORT_READY_TO_START to work by ckecking "wait for printing trigger", but the measurement are still taken before automatic page breaks.

    I have tried both setTimeout and requestAnimationFrame. Is there no way to await chrome-pdf's automatic page breaking before taking measurements?


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.