Skip to content

fix(html): print a sheet onto the page, without our ruler - #817

Merged
andiwand merged 1 commit into
mainfrom
fix/print-a-sheet-onto-the-page
Sep 5, 2026
Merged

fix(html): print a sheet onto the page, without our ruler#817
andiwand merged 1 commit into
mainfrom
fix/print-a-sheet-onto-the-page

Conversation

@andiwand

@andiwand andiwand commented Sep 5, 2026

Copy link
Copy Markdown
Member

🤖 Generated with Claude Code

The first, self-contained part of #816: the sheet is fitted to the paper it is printed on, and the ruler stays off it. Print only — no public API, no parser, no change to what the screen shows.

Why

translate_sheet writes one <col> per column carrying the document's own width as width and min-width, under table-layout:fixed, so the table is exactly as wide as the file says. On screen that is right, and the viewport fit hides it. On paper nothing relates it to the page: the only @media print rule we ship pins the zoom back to actual size, correctly, and nothing fits the sheet afterwards. What is left is the browser's own shrink-to-fit — silent when it gives up, bounded, and different per browser and print path. A desktop dialog has a scale control on top of it; the Android print framework offers the user none, which is the asymmetry in opendocument-app/OpenDocument.droid#644.

The ruler makes it worse: the gutter and the <thead> of column letters are ours, not the file's, and a spreadsheet application prints neither.

What it does

@media print{
.odr-sheet thead{display:none}
.odr-sheet-gutter{visibility:collapse;width:0}
.odr-sheet-row-header{visibility:collapse;padding:0;box-shadow:none}
.odr-sheet{max-width:100%}
.odr-sheet col{min-width:0!important}
}
  • max-width fits the sheet to the page box; !important is what beats the width written inline per column. A sheet narrower than the page is untouched — max-width only bites above it.
  • The gutter collapses rather than display:none: removing those cells takes them out of their rows and shifts every column one to the left, which I measured before settling on this. The cells state visibility:collapse too, for a browser that collapses no column.

Measured

Chrome headless --print-to-pdf, Letter, text recovered with gs -sDEVICE=txtwrite. A 12-column × 1.5in sheet rendered by translate from a flat ODF:

columns printed
before 8 of 12
after 12 of 12

odr-public/ods/file_example_ODS_10.ods (7.50in incl. ruler, fits today): identical printed text before and after except the ruler's letters and numbers — no cell gained or lost.

Across widths, on the same markup:

column width (8 columns) today ruler off this PR
0.95in 8/8 8/8 8/8
1.6in 7/8 8/8 8/8
3in 4/8 5/8 8/8

So dropping the ruler alone buys about one column of width and is not a fix by itself, as #816 says.

What it does not do

The fit is a shrink, not what a spreadsheet application does. Columns narrow toward, but not below, their content, so relative widths compress rather than scale: at 8 × 3in on Letter every column comes out equal. A very wide sheet prints small rather than paginating column-wise. Honouring the file's page style — paper, orientation, fit-to-pages, print ranges, repeated headers — needs Sheet::page_layout(), which does not exist, and column-wise pagination needs slices html cannot express for a table. #816 stays open for that decision.

visibility:collapse on a <col> is verified in Blink; WebKit is the untested half, and the width:0 plus the cells' own visibility are the fallback for a browser that only hides the column.

Reference output

Unchanged, and no pin moves. The suite renders with embed_shipped_resources = false, so the stylesheet lives in resources/ — which the CI comparison does not cover; it compares output/, and a print-only rule moves no screen pixel there.

Test

html.a_printed_sheet_drops_the_ruler_and_fits_the_page renders an .ods and checks the print rules are emitted and the screen ones — the inline column widths, table-layout:fixed, the ruler markup — are still there.

A spreadsheet is laid out at the width the file states — one `<col>` per
column carrying the document's own width, under `table-layout:fixed`.
Paper cannot scroll, so what did not fit was cut off along the right edge
once the browser's own shrink-to-fit gave up: silent, bounded, and
different per browser and print path. A phone print has no scale control
to correct it with, which is where it was reported.

`@media print` fits the sheet to the page instead, and leaves off the row
and column ruler, which is ours rather than the file's and took about a
centimetre a page has none of to spare. The screen view is untouched.

Towards #816, opendocument-app/OpenDocument.droid#644.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Fp26La4hFAu9VRMHPjKmXd
@andiwand
andiwand force-pushed the fix/print-a-sheet-onto-the-page branch from ee58f5c to 3813aaa Compare September 5, 2026 20:22
@andiwand
andiwand merged commit 41c6405 into main Sep 5, 2026
23 checks passed
@andiwand
andiwand deleted the fix/print-a-sheet-onto-the-page branch September 5, 2026 20:22
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