Zend PDF mixes up Width and Height of a Page
-
16-03-2021 - |
Question
I'm using Zend_Pdf, and at one point I am reading my source page's Width and Height using $page->getWidth();
and $page->getHeight();
Most of the time it reads fine.
Sometimes, however, Zend PDF returns are the opposite - it shows 11in as width and 8.5in as height for a standard Letter-sized PDF. I can't figure out why it would do that.
I tried saving the PDF in question as 1.4, as PDF/A, but the result is all the same.
Solution
After a bit of investigation I was able to figure it out.
Turns out the page was coded as having "Rotate" set to 270 degrees.
You can access this variable inside Zend_Pdf_Page:
$this->_pageDictionary->Rotate->value
Then if Rotate is set to 90 or 270, I reverse Width and Height.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow