We have a system that dynamically switches from a 1 page portrait calendar to a 2 page landscape calendar once there is too much text to fit on a single page. Currently we do this server-side, using a different template for each orientation and estimating whether it will be too much for one page. But this is messy because we have to estimate the number of lines based on estimated font widths and estimated line breaks in order to guess when to switch from 1 page to 2 pages, and its really tough to do accurately. With javascript it would be much easier to simply detect when the content gets too big for the single page and restructure the html a bit into two landscape pages and set a few different css classes. I'd like to switch to this method, but this brings up two questions:
1) Currently we set page orientation on the server side using the PDFCrowd python API:
client.setPageWidth('8.5in')
client.setPageHeight('11in')
or
client.setPageWidth('11in')
client.setPageHeight('8.5in')
Can this be set somehow in the html or via javascript, so the page orientation of the pdf will switch between portrait and landscape?
2) Will the rendering engine wait until all javascript is executed and the page's DOM is restructured before converting it to an html? In other words, I am wondering whether, if we add javascript code that changes the DOM structure from an initial portrait page to two landscape pages, which runs inline right when the page loads, whether we can be sure this will finish executing before pdfcrowd takes a snapshot of the html for a pdf. Can you provide some insight into how you determine when to actually render and how much DOM manipulation via javascript can reliably be done when the page is loaded or loading?