Page sizes (aka page borders) are defined in the page dictionary:
/MediaBox : physical media boundaries (pages). This value is required, so you will find it in every PDF file./CropBox : The area that is visible when displayed or printed. The value of /CropBox is equal to or less than /MediaBox . This value is optional; if it is absent, /CropBox is equal to /MediaBox .- Other possible values ββare
/BleedBox , /TrimBox and /ArtBox . They have been defined for specific purposes, but they are no longer used as often. If they are missing, they default to /CropBox . None of these values ββcan exceed the value of /CropBox .
When you create a document using iText, you define /MediaBox explicitly or implicitly.
Explicit:
Rectangle rect = new Rectangle(20, 20, 300, 600); Document document = new Document(rect);
Indirectly:
Document document = new Document();
This single line is equivalent:
Rectangle rect = new Rectangle(0, 0, 595, 842); Document document = new Document(rect);
The four parameters passed to the Rectangle constructor ( llx , lly , urx , ury ) define the rectangle using the x and y coordinates of the lower left and upper right corners.
In the case of new Rectangle(0, 0, 595, 842) lower left corner of the page coincides with the origin of the coordinate system (0, 0) . The upper right corner of the page coincides with the coordinate (595, 842) .
All dimensions are defined in user units, and by default user units roughly correspond to the printing point: 1 user unit = 1 point.
Pay attention to the word roughly: we use points to perform calculations, but in the ISO standard we are very careful not to use a point as a synonym for a user block. For example: on an A4 page of 595 for 842 user units, but if you calculate the exact value in points, there will be a slight difference (some digits after the point).
The bottom left corner of the page is not always the source of the coordinate system. If we define a page using a Rectangle(20, 20, 300, 600) , the origin is 20 user units below and 20 user units to the left of the lower left corner. You can also use negative values ββto determine page size.
For example: suppose you want to create an A2 document consisting of 4 A4 pages, than you can determine the page sizes as follows:
Rectangle(-595, 0, 0, 842) Rectangle(0, 0, 595, 842) Rectangle(-595, -842, 0, 0) Rectangle(0, -842, 595, 0);
By defining a media field like this, you also transmit information regarding the relative position of different pages. If you look at 4 A4 pages as a unit, then the exact center of page A2 is the coordinate source.
Important:
All of the above assumes that you have not introduced any coordinate transformations, for example. using the concatCTM() or transform() method. These methods allow you to change the coordinate system, for example, change the angle between the x and y axis from 90 degrees (default) to another angle. You can also scale the axis to get a different aspect ratio. Although it is, of course, interesting to do this, it requires quite a bit of math.