A 760-Pixel SVG Diagram Against a 182mm Print Column
A generated 760px SVG works out to about 201mm, while the A4 text column is 182mm. One template rule and an ink-bounds probe closed the gap.
TL;DR
Generated SVG diagrams were authored at 760px, which overflows the 182mm A4 print column by about 19mm. The fix adds a shared stylesheet rule sizing figures at 100% width with auto height, so every report in the family inherits correct print sizing. An ink-bounds probe confirmed zero violations across reprinted PDFs.
A 760-Pixel SVG Diagram Against a 182mm Print Column
The KotaPortal architecture report was nearly assembled: eight A4 pages, sixteen sections, and three diagrams generated as SVG by the report tooling. The browser preview looked right, with every figure sitting neatly inside a wide viewport. The last step in the pipeline is a Playwright print run, and figure sizing was still an open question there.
Each generated diagram carries a fixed authored width, width="760" on the SVG root. Printed on A4, that width does not survive contact with the page.
The arithmetic the screen hides
A4 paper is 210mm wide. The shared family stylesheet, report-template.css, declares the page box with margins of 16mm 14mm 18mm 14mm [2], which leaves 14mm on the left and 14mm on the right. The usable column is 210 minus 2 times 14, so 182mm. At the CSS reference resolution of 96 dpi, an authored figure width of 760px converts to about 201mm.
The figure is roughly 19mm wider than the print column it has to live in. In print that is not a matter of taste. The ink runs past the margin or gets cut, and a browser tab shows nothing about it.
The assumption I started with was that the PDF step would take care of it. Playwright's documentation for preferCSSPageSize gives any CSS @page size declared in the page priority over what is declared in width and height or format options; it defaults to false, which will scale the content to fit the paper size [4]. Paper size then follows the template, so the pages come out A4 with the right margins.
Fitting the paper is not fitting the text area. Figure width is a separate axis, and the page-level option says nothing about it.
CSS does have the answer, and it is narrower than expected. The width property with a percentage value defines the width as a percentage of the containing block's width, and the CSS width value overrides any width attribute set on the SVG element [3]. One percentage on the figure therefore resolves against the 182mm column and discards the authored 760. Without that rule, the SVG keeps its own attribute and takes its 201mm wherever it wants.
The print media type is intended for paged material and documents viewed on a screen in print preview mode [1]. Screen layout is a different medium, and it says nothing about where ink lands on paper.
Figure sizing belongs to the template
The fix went into the shared report-family stylesheet instead of the one report that surfaced the problem. One rule, and every document in the family inherits it.
@page {
margin: 16mm 14mm 18mm 14mm; /* A4, 210mm - 2x14mm = print text column 182mm */
}
.sop-diagram img {
width: 100%; /* diagram figures fill the text column (182mm) for print legibility */
height: auto;
display: block;
}
The template comment states the contract: diagram figures fill the text column (182mm) for print legibility, and the SVGs are authored at 760 px and scale proportionally. height: auto keeps the aspect ratio, since the diagrams have no fixed height worth preserving.
Placing the rule in the template rather than in the report page has a second effect. When the whole family was re-printed under the new rule, the older data-architecture report picked it up too, with no edit in that document. Figure width is now the family's business, not each report's.
Verified by ink bounds, not by eye
A print run is not checked by staring at a browser tab. The verification used here is mechanical: an ink-bounds probe rasterizes every PDF page at 150 dpi and reports any page where ink crosses the allowed bounds. The re-print of the report family under the new rule reported 0 violations.
That number is the post-fix result only. The pre-fix output was never probed, so there is no measured failure to quote. The overflow is arithmetic: 201mm of figure inside an 182mm column. A known geometric fact and a logged probe result are worth keeping apart.
@page targets and modifies the page's dimensions, orientation, and margins, and its size descriptor specifies the target size and orientation of the page box's containing block [2]. The figure rule sits next to it in the same file, sized against the same geometry. That pairing is the durable part of this change: generated figures are sized against the family's page contract, not against the pixel width they were authored at, and the claim is confirmed by the probe rather than by a screenshot.
The next report in this family will not need a figure-sizing fix. That is no longer the report's job.
Sources
- [1] MDN Web Docs, "print" media type on the @media rule developer.mozilla.org
- [2] MDN Web Docs, @page rule developer.mozilla.org
- [3] MDN Web Docs, width property developer.mozilla.org
- [4] Playwright docs, page.pdf() options playwright.dev