fix: print the canvas exactly, with no added whitespace - #382
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three things in the print stylesheet put white on the page or changed how the
diagram looked.
height:autosized 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.
htmlandbodyhad no height, so a100%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".
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
@pagewithpreferCSSPageSize:not the default paper
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 inprintDocument.test.jsyarn build— cleanCloses #227