Forum How do I...?

Dynamic number of pages

Hello Dears,

I'm trying to generate all the pages and their content dynamically from JS, and it works on the browser but the generated PDF contains only one page.

Is this a limitation or do I need to handle it in a specific way?

Please ensure that the JavaScript is actually running by enabling it with the -j flag, check the Prince output log for any errors or warnings, and see if the document content is contained within a single inline-block or similar element that cannot be split across multiple pages.
Many thanks for your quick reply.

I've found where is the issue, and it's that I'm trying to get the height of an element created programmatically in JS but the value of the height is undefined using the:

1. offsetHeight
2. clientHeight

and still no idea how to get the hight
Unfortunately Prince runs JavaScript before performing layout, so the height will not be available. It is possible to run Prince twice, with the first pass capturing relevant dimensions from the box tracking API and then providing them to the second pass, however this is different to how it works in browsers.