Skip to main content
Skip table of contents

How to get the page width and height of a PDF document?

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 = pdfDoc.getPage(page).getMediaBox();

Do you want the rotation?

int rotation  = pdfDoc.getPage(page).getRotation();

Do you want the combination of both?

Rectangle pagesize = pdfDoc.getPage(page).getPageSizeWithRotation();

Do you want the CropBox?

Rectangle cropbox = pdfDoc.getPage(page).getCropBox();

These are some java methods that will give you information about the dimensions of a page (the same in C#). 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. Variable page is the integer number of page you are interested in.

Click this link if you want to see how to answer this question in iText 5.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.