Skip to content

Fix two-page PDF export on macOS#3

Closed
yihui wants to merge 2 commits into
mainfrom
fix-pdf-two-page
Closed

Fix two-page PDF export on macOS#3
yihui wants to merge 2 commits into
mainfrom
fix-pdf-two-page

Conversation

@yihui

@yihui yihui commented Jul 6, 2026

Copy link
Copy Markdown
Owner

lt_export() to PDF produces a two-page file on macOS GHA runners
(e.g. examples/01-lt.pdf), though it is a single page on Linux. The
1px @page height buffer (a972a61) did not resolve it.

This PR temporarily replaces the site build with a debug script
(debug-pdf.R) that runs on macos-latest to capture the measured
screen-media size vs the print-media height, page counts across several
@page height buffers, and the resulting MediaBox. Once the root cause
is pinned down, the fix will replace the debug scaffolding.

Not ready for merge — debug scaffolding present.

🤖 Generated with Claude Code

yihui and others added 2 commits July 6, 2026 16:31
scrollHeight returns an integer floor of the actual content height; on
macOS, font metrics (San Francisco) can make the rendered table 0.x px
taller than the measured value, causing the PDF to spill onto a second
page. Adding 1px to the @page height absorbs this sub-pixel difference
without visibly enlarging the crop.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
lt_measure() reads body.scrollWidth, which is the integer floor of the
table's fractional natural (max-content) width. lt_export() then pins the
body to that floored width for the PDF pass. Being a sub-pixel narrower
than the content, a cell would wrap, growing the table taller than the
measured height and pushing the PDF onto a second page. This reproduced on
macOS (Google Chrome) but not Linux (Chromium), because their font metrics
round differently.

Fix: add 1px to the measured width so the body is never narrower than the
content and never re-wraps. Replaces the earlier 1px height buffer (wrong
axis). Adds a regression test exporting a wide, long-labelled table to a
single-page PDF.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yihui

yihui commented Jul 6, 2026

Copy link
Copy Markdown
Owner Author

Squashed the fix directly onto main in 0070122 (folded into the failed a972a61). Closing.

@yihui yihui closed this Jul 6, 2026
@yihui
yihui deleted the fix-pdf-two-page branch July 6, 2026 21:08
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