Legacy notice!

iText 5 is the previous major version of iText's leading PDF SDK. iText 5 has been EOL, and is no longer developed. Switch your project to iText 7, integrating the latest developments.
Check related iText 7 content!

I have a PDF, and I want to get the width and height of each page using iTextSharp.

This is what I have so far:

string source=@"D:\pdf\test.pdf";
PdfReader reader = new PdfReader(source);

Posted on StackOverflow on Aug 13, 2013 by Mohamed Kamal

Do you want the MediaBox?

Rectangle mediabox = reader.GetPageSize(page);

Do you want the rotation?

int rotation = reader.GetPageRotation(page);

Do you want the combination of both?

Rectangle pagesize = reader.GetPageSizeWithRotation(page);

Do you want the CropBox?

Rectangle cropbox = reader.GetCropBox(page);

These are some methods that will give you information about the dimensions of a page. Most of them return an object of type Rectangle that has methods such as getWidth() and getHeight() to get the width and the height of the page. Other useful methods are getLeft() and getRight() as well as getTop() and getBottom(). These four methods return the x and y coordinates that define the boundaries of your page.