Skip to content

fix(html): print one page box to a sheet - #1197

Merged
andiwand merged 2 commits into
mainfrom
fix/print-page-boxes
Oct 10, 2026
Merged

andiwand merged 2 commits into
mainfrom
fix/print-page-boxes

Conversation

@andiwand

@andiwand andiwand commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

A user reported that a pdf printed from the mobile apps has the wrong layout. Both apps print every document through the web view, a pdf too: the Android PdfDocumentAdapter overload has no caller. So what prints is our HTML, and the fixed-page views had no print rules.

Before

Chrome --print-to-pdf of the current output:

  • The grey backdrop (#525659), the 16px gaps and the shadows print.
  • The page boxes break across sheets: the 9-page Casio_WVA-M650-7AJF.pdf printed on 10 sheets, each with parts of two pages. Slides do the same: 6 slides of style-various-1.odp on 4 sheets.
  • A landscape page shrinks onto a portrait sheet.
  • A text page with margins gets the margins twice: the browser's and the page box's.

Change

  • document.css: @media print takes the backdrop, the gaps, the padding and the shadows off .odr-pages and .odr-page-outer, and breaks after each page box.
  • document.cpp: a paged view writes an @page rule with the size of the first page. A text page puts its margins on the sheet and drops them from .odr-page-inner, so text that runs past a sheet keeps them.
  • pdf_file.cpp: the same print rules for .d/.p. Each page box gets a named @page for its size, so a pdf that mixes portrait and landscape pages prints each sheet in its own orientation. .p gets content-visibility:visible in print, because WebKit prints an off-screen content-visibility:auto page blank.
  • frontend.cpp: the dark style is gated on screen. Before, a dark render printed a black backdrop, a shadow and a dark page, or light-grey text on white paper. Now a print always uses the light style.

Verification

I printed the output of 13 corpus files (pdf, odp, pptx, key, odg, odt, docx, md, xlsx). I used Chrome through CDP Page.printToPDF in three ways: with the CSS page size, and with the paper forced to A4 and to Letter, the way the Android print framework picks it. I also used WebKit through WKWebView.printOperation on macOS with A4 and Letter, as the nearest stand-in for the iOS print path.

  • Chrome, all three ways: one sheet for each page box, in the correct orientation, with no grey. When the paper is not the page size, Chrome scales the page onto the sheet.
  • WebKit: one sheet for each page box, with no blank pages. WebKit ignores @page size and only shrinks to fit the paper width. So an A4 page on Letter paper still breaks over two sheets in WebKit, as before. CSS cannot fix this: in WebKit print layout vh is the height of the window, not of the paper. On iOS, the app can choose the paper with UIPrintInteractionControllerDelegate.printInteractionController(_:choosePaper:).
  • Screen: the screenshots of six samples before and after are byte-identical.
  • Text without page margins and spreadsheets print as before.

I did not test on a phone.

Reference output

Every paged and every pdf output changes: a new <style> in the head, and a q class on each pdf page. So compare-html needs a reference-output update. That update is not in this PR yet.

andiwand and others added 2 commits October 10, 2026 10:50
The pdf view, slides, drawing pages and text pages with margins printed
the viewer as it is on screen. The grey backdrop and the gaps printed,
the pages broke across sheets, and a landscape page shrank onto a
portrait sheet.

In print, the page column now drops the backdrop, the gaps and the
shadows, and it breaks after each page box. An `@page` rule gives the
sheet the size of the page, and a pdf names one page for each size. A
text page puts its margins on the sheet, so text that runs past a
sheet keeps them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KNpfqA2jL1iVM1Wirf7njH
The dark style came after the print rules, so a dark render printed a black
backdrop, a shadow and a dark page, or light-grey text on white paper. Gate
the dark style on screen, so that a print always uses the light style.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S5yx1nDeVcNX3BxqK1WpJz
@andiwand
andiwand force-pushed the fix/print-page-boxes branch from d924eb9 to 83fab80 Compare October 10, 2026 08:52
@andiwand
andiwand merged commit 51e45ef into main Oct 10, 2026
23 checks passed
@andiwand
andiwand deleted the fix/print-page-boxes branch October 10, 2026 08:53
andiwand added a commit that referenced this pull request Oct 10, 2026
The output now has the print rules of #1197, and the whole-sheet reads of
formulas that do not parse from #1193.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S5yx1nDeVcNX3BxqK1WpJz
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.

1 participant