[Public] Understanding Rectangle Construction and Positioning in IronPDF
When drawing rectangles in PDF documents using IronPDF, it's important to understand that its coordinate system and behavior differ from other libraries like IronOCR and IronBarcode. While IronOCR and IronBarcode define rectangles relative to an image input, IronPDF operates within the coordinate space of the PDF document itself.
The image below illustrates how changes to the x
, y
, width
, and height
values affect rectangle positioning in IronPDF:
-
Coordinate Origin:
The origin point(0, 0)
in a PDF document is located at the bottom-left corner of the page. However, when specifying a rectangle, this origin is treated as the top-left corner of the rectangle, which affects the direction in which the shape is drawn. -
Y-Coordinate Behavior:
Increasing they
value moves the rectangle upwards, while decreasing it moves the rectangle downwards. Providing a negativey
value places the rectangle below the(0, 0)
point. -
X-Coordinate Behavior:
Increasing thex
value moves the rectangle to the right. Conversely, decreasing or supplying a negativex
value shifts the rectangle to the left. -
Width Behavior:
A positivewidth
value draws the rectangle to the right from the starting point. A negative or decreasing width draws the rectangle to the left. -
Height Behavior:
A positiveheight
value extends the rectangle upwards, while a negative height draws it downwards from the starting point.