Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iTextSharp A4 size rounding

According to the ISO standard, A4 is 210x297 mm, or about 595.2756x841.8898 points. Is there any reason why in iTextSharp, the point values are rounded, ie. 595x842, even though they are floats?

enter image description here

like image 687
fejesjoco Avatar asked Apr 12 '15 17:04

fejesjoco


2 Answers

I am a member of the ISO committee responsible for the PDF standard. The standard defines that all measurements in PDF are expressed by user units (NOT points).

One user unit by default roughly corresponds with one typographic point, but the ISO committee is aware of the fact that they are not exactly the same.

This is indeed a cause for confusion. I am currently preparing for the ISO meetings in San Jose that start next week. We are working on ISO-32000-2 (PDF 2.0) and although ISO-32000-1 was already in good shape, we still found some instances where it said point instead of user unit and we'll replace point by user unit in ISO-32000-2..

Bottom line: it is commonly accepted that an A4 page in PDF measures 595 by 842 user units (probably because integer values were preferred over real values) and that's why it's implemented that way in iText.

like image 162
Bruno Lowagie Avatar answered Oct 25 '22 11:10

Bruno Lowagie


They are not rounded and obtained at runtime. PageSize.A4.Right and PageSize.A4.Top are two values of the rectangle (width, height) defined for the A4 type (which is an internal class in iTextSharp). From the PageSize.cs:

  /** This is the a4 format */
  public static readonly Rectangle A4 = new RectangleReadOnly(595,842);

As you see it is nothing to do with rounding.

EDIT:

See Bruno answer for an exact explanation of the issue. Citing his comment:

The key is that user units correspond with points, but aren't defined as being equal to points

like image 43
codingadventures Avatar answered Oct 25 '22 10:10

codingadventures