Is there a way to detect the orientation of every page in a pdf file?
I am creating an application that adds watermarks(text) to pdf files. These files can have pages portrait, landscape or a combination of both.
Using the doc.MediaBox property, I use the following logic below:
portrait = box.Height > box.Width
My problem is that, it is always returning a true value even on a landscape documents.
Landscape pages can be created in 2 ways: set a width larger than the height or set the page rotation to 90 or 270 degrees for a portrait page. Pseudo-code for determining if a page is portrait or landscape would look like this:
I'm not familiar with ABCPDF but I assume you have access to page rotation.
There are two ways that orientation can be implemented within a PDF.
The correct way is to specify a rotation angle for the page. You can get the rotation of the current page using code of the following form.
#
However sometimes page orientation is implemented by setting the MediaBox to a wide rather than high page size. You can check the current MediaBox using the Doc.MediaBox property.
A Doc can have a different MediaBox on every single page. To inspect the Mediabox for page N: