Hi!
Maarten wrote:
Using the "PdfPage.width = value" removes all contents.
Most likely it does not remove the contents. You expect to see the top half of the page, but what you still see could be the bottom half of the page. The contents are still there, they are just outside the visible area.
Maybe try playing around with the MediaBox to make sure you see the part where you added contents.
Or maybe create a second PDF page with the desired size and draw the oversized page on this page. This adds a few extra bytes to the PDF file.
The best way: determine the page size you need before creating the final contents. Call your code twice: first time to determine the correct page size (discarding the page created in this run), second time to draw the correct page.
Use caching if you access databases or do other "slow" things in the code.