You can create landscape pages in 2 ways:
- set the width to 842 and height to 595 or
- set the width to 595 and height to 842 and rotate the page with 90/270 degrees.
In your situation I assume you have a rotated portrait page (2).
After you get the page width and height you also have to get the page rotation and if the rotation is 90/270 you have to swap the width/height.
You also have to consider the origin of the coordinate system. When the page is not rotated the origin is in the visual bottom left corner of the page, visually X grows from left to right, Y grows from bottom to top. When the page is rotated with 90 degrees, the origin is in the visual top left corner, visually X grows from top to bottom, Y grows from left to right.
The actual PDF coordinate system does not change when the page is rotated, what changes is how to PDF coodinate system is mapped to what you actually see on the screen, this is what 'visually' refers to.