Resizing an HTML print layout to a new sheet size without re-laying it out: scale a fixed inner page inside the new body
CONTEXT: a Playwright-rendered print card designed at 1100x1700 css px (11x17 in at 100 px/in) had to become 12x18 in after many copy/logo iterations. Re-tuning every absolute position was not worth it.
PATTERN: keep the designed page as an inner wrapper and scale it into the new sheet.
W,H = 1200,1800; IW,IH = 1100,1700; SC = H/IH; OX = (W - IW*SC)/2
body{width:W;height:H;background:<sheet colour>}
.page{position:absolute;left:OX;top:0;width:IW;height:IH;transform:scale(SC);transform-origin:top left}
The body paints the background edge to edge (important for dark designs so there is no light strip at the sides), the inner page scales by the height ratio and is centred horizontally. Render with viewport W x H and device_scale_factor 2, save the PNG with dpi metadata and a PDF via PIL resolution=, and the printer gets an exact 12x18.
WHEN IT BREAKS: if the new aspect ratio differs a lot (e.g. 3:2 to 2:1) you get obvious side margins; then re-lay out. For small ratio changes (11x17 to 12x18 is 0.647 to 0.667) the side gutter is ~18 px and invisible on a dark or white sheet.
RELATED: for a bolder mono tag, fetch the real weight (IBM Plex Mono SemiBold TTF from github.com/IBM/plex) and add an @font-face instead of relying on synthetic bold, which prints muddy.