Discussing the article: "Building a PDF Creation Library in MQL5 (Part 4): Lines Boxes and Color"

Check out the new article: Building a PDF Creation Library in MQL5 (Part 4): Lines Boxes and Color.

The article turns drawing primitives into PDF output: one cm flip installs a top‑left, y‑down system, while CPdfPage writes m/l/c/h/re, S/f/B, W n, and transforms from calls on CPdfSurface. PdfColor keeps RGB bytes and fixes MQL5 byte order when writing fractions. It also covers caps, joins, dashes, clipping, and Bezier circles. Demos include a printable ruler, a feature sampler, and a ready letterhead script.

Real documents need more than text. They also need headers, borders, colored panels, logos, and separators. These elements require a drawing system that can work alongside text rather than relying on it. After Part 3, the library can generate a valid, paginated PDF using four files: PdfBuffer.mqh (which manages bytes, with Length() returning the current offset), PdfWriter.mqh (which manages object numbers, recorded offsets, and the cross-reference table), PdfValidate.mqh (Part 2's validator), and PdfDefines.mqh (shared constants).

However, three limitations become apparent as soon as we want to create a properly designed page. Everything on the page is still text; coordinates are measured from the bottom-left corner, opposite to the coordinate system normally used in page layout; and all content is black unless a color is explicitly specified.

This part addresses all three limitations. The page adopts a top-left origin, with the y-coordinate increasing downward, and supports millimeters as a measurement unit. A path model provides the foundation for drawing lines and shapes, while a dedicated color type stores color components as bytes and writes them as fractions. 

Author: Sandro Begashvili