Skip to content

Scale layout to a wide viewport, then fit the print column - #1

Merged
tannevaled merged 1 commit into
mainfrom
viewport-scale-fix
Sep 4, 2026
Merged

Scale layout to a wide viewport, then fit the print column#1
tannevaled merged 1 commit into
mainfrom
viewport-scale-fix

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Summary

  • Fixes page-count bloat on pages with a fixed-width desktop sidebar (found via corpus/): Export now lays out at Options.ViewportPx (default 1024px) and scales the result to fit the print column, instead of laying out directly at the print column's own (~642px) width.
  • RFC 9110 428→120 pages, pkg.go.dev/net/http 86→49, Wikipedia 34→18 — see corpus/CORPUS.md for the full before/after across all 8 corpus pages. Extracted text length is unchanged on every page (density change, not a content change).
  • Splits the former single html2pdf.go into atoms.go (pagination), fonts.go (font loading/selection) and render.go (the PDF paint pass), each with its own doc comment.

Test plan

  • go test ./... green (both modules)
  • gofmt -l . / go vet ./... clean
  • Full corpus re-run against all 8 public pages, visually spot-checked (RFC 9110 and Hacker News page 1 previews in corpus/out/)

🤖 Generated with Claude Code

RFC 9110's HTML edition (and, to a lesser degree, every other corpus page)
rendered technically correctly but page-bloated: laying out directly at the
print column's own width (~642px for A4/20mm) sits below the breakpoint a
real desktop-oriented page relies on to drop a fixed-width sidebar, so the
sidebar just squeezed the prose into a sliver instead.

Options.ViewportPx (default 1024px) now sets the width a page is laid out
against; Export scales the whole result down to fit the print column, same
idea as a browser print dialog's "shrink to fit". Corpus effect: RFC 9110
428->120 pages, pkg.go.dev/net/http 86->49, Wikipedia 34->18, extracted text
length unchanged (a density change, not a content change) — see
corpus/CORPUS.md for the full before/after table.

Also split the former single html2pdf.go into atoms.go (pagination),
fonts.go (font loading/selection) and render.go (the PDF paint pass), each
with its own package-level doc comment.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit fee2c2a into main Sep 4, 2026
1 check passed
@tannevaled
tannevaled deleted the viewport-scale-fix branch September 4, 2026 13:19
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