21

Anyone knows what unit system does iTextSharp uses? My first assumption would be pixels but I'm not sure about it.

Thanks!

EDIT: Sorry to not being more specific, and thanks for letting me know. I'm talking about units for measures in the PageSize and Margins.

Sebastian
  • 1,491
  • 6
  • 20
  • 29
  • 1
    PageSize and Margins both use the same units as everything else (points). So a left margin of 36 would be a half inch margin. – David Sep 16 '09 at 19:07
  • 2
    However I think both of those are a bit difficult if you want an exact value, since the easy way of setting them expects an int (restricting you to even multiples of 1/72 of an inch, not nice if you need to match a metric page template). I can't remember if you could define a custom page template to get around that or if it was a limitation baked into the PDF standard. – David Sep 16 '09 at 19:12
  • 5
    It's really obnoxious when documentation for a library says something like "int waitDuration - the duration to wait" without specifying the units of measure. I would be embarrassed to put out documentation with meaningless descriptions like that. Here, iTextSharp documentation says "Parameters: pageSize - the pageSize" Thanks a lot! – Jason Kleban Jul 01 '13 at 17:57
  • Pixels would be completely useless, as the scale at which it renders will then be completely determined by the screen or printer resolution. So an A4 document made for a 600dpi printer would come out _huge_ on a typical screen, and be squashed to A6 when printed on a 1200dpi printer. For this reason, I would surmise that PDF doesn't support the pixel as a unit. – Stewart Aug 23 '23 at 10:53
  • @JasonKleban Indeed. But I see that `Document.PageSize` is of type `Rectangle`. So there is a question: does the `Rectangle` class represent a rectangle of specified _physical_ size and position, or an abstract collection of numbers that can be interpreted in any unit depending on context? This in itself unclear to me at the moment. If the former, the documentation for `Rectangle` is where unit should be indicated. If the latter, it should indeed be in the documentation for `PageSize`. – Stewart Aug 23 '23 at 11:03

2 Answers2

27

If I remember correctly it uses "points", the same unit of measurement as a font (as PDF is centered around correct font rendering).

One "point" is 1/72 of an inch (or about 0.353mm).

David
  • 24,700
  • 8
  • 63
  • 83
6
pointsValue = iTextSharp.text.Utilities.MillimetersToPoints(mmValue)

and more options here https://sourceforge.net/p/itextsharp/itextsharp/ci/31e03918bb1eedc8f0d9efe56b982dfcee7aaa4d/tree/src/core/iTextSharp/text/Utilities.cs#l189

fedeteka
  • 943
  • 1
  • 14
  • 33