Skip to content

docs(examples): rebuild the Book template flagship on the v1.9 book primitives#245

Merged
DemchaAV merged 2 commits into
developfrom
feat/book-template-example
Jun 26, 2026
Merged

docs(examples): rebuild the Book template flagship on the v1.9 book primitives#245
DemchaAV merged 2 commits into
developfrom
feat/book-template-example

Conversation

@DemchaAV

Copy link
Copy Markdown
Owner

Why

The BookTemplateExample is the document whose construction drove the whole v1.9 book-primitives series (#228#244) — but it was never migrated onto the APIs that series shipped. It still assembled itself the old way (and was untracked, reaching into PDFBox transitively, wired into no batch):

  • three DocumentSessions glued with PDFBox PDFMergerUtility,
  • a throwaway layoutSnapshot() pass to learn chapter page numbers,
  • a hand-computed dot-leader width, square-dash leaders, paragraph-only bookmarks.

This closes the loop: the flagship now renders without any of the workarounds the series removed.

What changed

Rebuilt the book in one DocumentSession, each part on the API that replaced its workaround:

Was Now
cover + body as separate sessions + PDFMergerUtility pageMargins(List.of(PageMarginRule.page(1, DocumentInsets.zero()))) — page 1 bleeds, the rest keep book margins
two-pass layoutSnapshot() probe for TOC numbers addTableOfContents(...) resolving each chapter's page in one pass from its anchor(...)
hand-computed LEADER_WIDTH, square dashes DocumentLeader.DOTS — a line().fill() leader with round caps
footer numbered from 1 incl. the cover DocumentPageNumbering.builder().showOnFirstPage(false)
paragraph-only bookmarks, no viewer prefs section bookmark(...) + chrome().viewerPreferences(openOutline())

No org.apache.pdfbox import, no two-pass probe, no manual leader math. Wired into GenerateAllExamples and the examples README flagship gallery, with a committed preview.

Verification

  • ./mvnw -f examples/pom.xml compile — green. Runs: Wrote …/book-template.pdf (6 pages).
  • Rendered and inspected: the cover's wave bands bleed to all four edges (page 1 zero margin); the Contents page shows dotted round-cap leaders with numbers 3 / 6 that match both the footer and the clickable GoTo link targets (fitz confirms internal links → page index 2 / 5); the outline lists Cover + both chapters; the cover page carries no footer number.
  • Engine/library unchanged — example-only change.

Follow-up to the book-template gap series; this is the end-to-end proof that G1–G8 are closed.

DemchaAV added 2 commits June 26, 2026 23:01
…rimitives

The Book template example — the document whose construction drove the v1.9 book
work — still assembled itself the old way: three DocumentSessions glued with PDFBox
PDFMergerUtility, a throwaway layoutSnapshot() pass to learn chapter page numbers,
and a hand-computed dot-leader width. It also reached into PDFBox (pulled in
transitively), was untracked, and ran in no batch.

Rebuilt on the APIs that replaced each workaround, in one DocumentSession: a
full-bleed wave cover via pageMargins(page(1, zero())); a clickable
addTableOfContents(...) whose DOTS leaders and live page numbers resolve in one pass
from chapter anchors; DocumentPageNumbering(showOnFirstPage=false) to leave the cover
unnumbered; section bookmark(...) plus viewerPreferences(openOutline()) so the reader
opens on the outline. No org.apache.pdfbox, no two-pass probe, no manual leader math.
Wired into GenerateAllExamples and the examples README flagship gallery, with a
committed preview.
Drop the stale 'Contents' bookmark from the outline description (the table of
contents emits no outline entry — the panel lists the cover and each chapter), and
move the example's import into the features.* group. Refresh the committed
book-template preview so its contents leaders sit on the baseline, matching the TOC
leader fix.
@DemchaAV DemchaAV merged commit 975a552 into develop Jun 26, 2026
11 checks passed
@DemchaAV DemchaAV deleted the feat/book-template-example branch June 26, 2026 22:57
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