Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get PDF page size with iTextSharp

Tags:

c#

itextsharp

I have a PDF document that I just received via file upload (InputFile).

I'd like to use iTextSharp to check it's page size before proceeding. For example, the size of a pdf when you go to file > Properties > Description Tab > Page Size (in acrobat).

Any advice on how I can do that?

THANKS!

like image 603
dpluscc Avatar asked Aug 13 '10 21:08

dpluscc


People also ask

How do you find the width and height of a PDF?

Once downloaded, simply open your pdf file in Adobe Acrobat Reader, press Ctrl+D or File > Properties (Document Properties). And voilà! In the Advanced Information section, you will find 'Page size'. Now, if you want to know your dimensions in units other than inches, simply convert it (1 inch -> 2.54 cm).

What is the size of PDF page in pixels?

By default, a chart is rendered as 500 pixels wide by 400 high. If you set a chart to have a specific width and height, like 5 inches wide by 2 inches high, it will be rendered in PDF as 480 pixels wide and 192 pixels high, and in HTML it would also be displayed at that pixel size.

What are the dimensions of a PDF page?

Most of us are familiar with typical document sizes such as letter (8.5″ by 11″), legal (8.5″ by 14″) and ledger/tabloid (11″ by 17″).

What is the height of a PDF page?

Note that iTextSharp defaults to a page size of A4 - which is 8.27 inches x 11.69 inches (slightly more elongated that the US Letter standard). This equates to 595 x 841 in points and 794 x 1122 in pixels.


1 Answers

You need to read the pdf from your input stream (m).

PdfReader reader = new PdfReader(m);
// Page size
Rectangle pagesize = reader.GetPageSize(1);
like image 184
Andreas Rehm Avatar answered Sep 17 '22 00:09

Andreas Rehm