19

What is the height of a regular PDF page in pixels?

I heard it was something like this:

Dim pgSize As New iTextSharp.text.Rectangle(595, 792)

but I am adding an image that takes up maybe half the height, and even though pgSize looks like a full page and the image takes up only half of it, I am getting a height of like 619 for the image?

I do not know if it is in the same units?

Community
  • 1
  • 1
Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062
  • 1
    iTextSharp uses a default of 72 pixels per inch. 792 would be 11", or the height of a standard Letter size paper. 595 would be 8.264", which is the standard width of A4 size paper. Using 595 x 792 as the page size would be a cheap and dirty way to ensure that you could print on either A4 or Letter without anything getting cut off. – Stewbob Dec 16 '09 at 03:49

3 Answers3

36

Your page size depends on what you set it when you create the document, probably using the PageSize object (eg. PageSize.LETTER).

Once you've established that, most elements in iTextSharp use points and 1 in = 2.54 cm = 72 points.

So if you used a standard letter page (8.5x11) it would be 612 by 792.

I'm not sure I understand your second question about the image, but I believe that all the units in iTextSharp are points.

sbrogers
  • 391
  • 3
  • 3
  • im having kind of a horrific time with this, im subtracting the heights of images each time from 792 – Alex Gordon Dec 15 '09 at 22:50
  • btw you sure its not 595 not 612? – Alex Gordon Dec 15 '09 at 22:55
  • Well, 8.5*72 = 612, but in reality you may have margins so the "usable" part of the page may be less than 612. If you can get your hands on a copy of the book iText in Action, I found it really helpful when I was first learning iText. And checking out some of their stuff in reflector is always helpful too. – sbrogers Dec 15 '09 at 23:01
  • i dont know if it would be much help all examples are in java – Alex Gordon Dec 15 '09 at 23:14
  • I found the examples close enough to c# to still be useful, as are the overall concepts presented. – sbrogers Dec 16 '09 at 00:12
  • One can prove this by hovering over the document properties (or exposing it directly) for a LETTER sized page, and it is indeed 612 x 792 – yoel halb Aug 07 '12 at 20:51
4

iTextSharp expresses dimensions in terms of points. They use the commonly accepted standard of 72 points per inch. You asked for measurements in terms of pixels, iTextSharp uses 96 pixels per inch, or an approximate conversion of 1.3333 * points = pixels.

So if your page size is 8.5 inches x 11 inches, in pixels it would be 816 x 1056. In points it would be 612 x 792.

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.

2
Dim xDoc as new Document(PageSize.A4)
Alex
  • 8,461
  • 6
  • 37
  • 49
V Malhi
  • 19
  • 6