Skip to content

fix: print the canvas exactly, with no added whitespace - #382

Merged
vibhavkatre merged 1 commit into
mainfrom
fix/print-fidelity-227
Aug 10, 2026
Merged

fix: print the canvas exactly, with no added whitespace#382
vibhavkatre merged 1 commit into
mainfrom
fix/print-fidelity-227

Conversation

@vibhavkatre

Copy link
Copy Markdown
Collaborator

Three things in the print stylesheet put white on the page or changed how the
diagram looked.

/* before */
@page{size:1280px 720px;margin:0}
html,body{margin:0;padding:0}
svg{display:block;width:100%;height:auto}

height:auto sized the drawing from its own aspect ratio rather than the page.
Whenever the page box was not exactly the canvas ratio — which is whenever the print
dialog falls back to the user's paper size — the leftover page height printed as a
white band. That is the reported extra whitespace.

html and body had no height, so a 100% had nothing to resolve against.

Background colours are dropped when printing unless asked not to, so a coloured
canvas came out white. That is the other half of "doesn't match the canvas exactly".

/* after */
@page{size:1280px 720px;margin:0}
html,body{margin:0;padding:0;width:100%;height:100%}
svg{display:block;width:100%;height:100%}
*{-webkit-print-color-adjust:exact;print-color-adjust:exact}

The same builder serves Print and the PDF fallback, so both improve.

Verification

I captured the exact document the app hands the print window, then rendered it the
way a printer does — Chromium honours @page with preferCSSPageSize:

  • the PDF page comes out 960 x 540 pt, which is exactly the 1280 x 720 px canvas,
    not the default paper
  • the drawing runs edge to edge: 0,0 to 1280,720 against a 1280x720 page
  • the amber canvas background survives the print instead of coming out white

Rendered page, for comparison with the canvas: the background fills the sheet and
both corner shapes sit where they do on screen.

  • yarn test — 916 pass, 6 new checks in printDocument.test.js
  • yarn build — clean

Closes #227

Three things in the print stylesheet put white on the page or changed how
the diagram looked.

`svg{height:auto}` sized the drawing from its own aspect ratio rather than
the page. Whenever the page box was not exactly the canvas ratio — which
is whenever the print dialog falls back to the user's paper size — the
leftover page height printed as a white band. It is `height:100%` now, so
the drawing fills the page box.

`html` and `body` had no height, so a `100%` had nothing to resolve
against.

Browsers drop background colours when printing unless asked not to, so a
coloured canvas came out white. `print-color-adjust:exact` keeps it.

The same builder serves Print and the PDF fallback, so both improve.

Verified by capturing the exact document the app hands the print window
and rendering it the way a printer does (Chromium honours @page with
preferCSSPageSize). The PDF page comes out 960x540pt, which is exactly
the 1280x720px canvas, and the drawing runs edge to edge — 0,0 to
1280,720 — with its background intact.

Closes #227

Co-authored-by: Vibhav Katre <vibhav@frappe.io>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
@vibhavkatre
vibhavkatre merged commit 202f182 into main Aug 10, 2026
3 checks passed
@vibhavkatre
vibhavkatre deleted the fix/print-fidelity-227 branch August 10, 2026 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Export][Bug] Print output doesn't match canvas exactly

2 participants