Skip to content

pdfkit: named destinations and GoTo links for in-document navigation - #22

Merged
tannevaled merged 1 commit into
mainfrom
named-destinations
Sep 3, 2026
Merged

pdfkit: named destinations and GoTo links for in-document navigation#22
tannevaled merged 1 commit into
mainfrom
named-destinations

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

What

External URI links (AddLink, #21) were navigable, but an in-document jump — a TOC entry, a cross-reference (\hyperlink/\hypertarget) — had no way to be clickable.

How

  • Page.AddNamedDest(name, x, y) anchors a jump target; Page.AddNamedLink(rect, dest) is a /Link whose /A is a GoTo action referencing a destination name.
  • Write collects every page's destinations, resolves each to its page, and emits the /Names /Dests name tree (names unique — first definition wins — and sorted, as a name tree requires), each mapping to [page /FitH y] so the viewer scrolls to the target and fits the page width.
  • A document with no destinations carries no catalog /Names.

Verification

Tests cover the /Names·/Dests·/GoTo·/FitH structure, duplicate-name deduplication, and the no-destinations path. 100% coverage, go vet, gofmt clean.

Enables clickable in-document navigation in go-tex/engine (a follow-up wires \hyperlink/\hypertarget).

🤖 Generated with Claude Code

External URI links (AddLink) were navigable, but an in-document jump — a table of
contents entry, a cross-reference — had no way to be clickable.

Add Page.AddNamedDest(name, x, y) and Page.AddNamedLink(rect, dest). A named
destination anchors a name at (x, y); Write collects every page's destinations,
resolves each to its page, and emits the /Names /Dests name tree (names unique —
first definition wins — and sorted, as a name tree requires), each mapping to
[page /FitH y] so the viewer scrolls to the target and fits the page width. A
named link is a /Link whose /A is a GoTo action referencing the destination name.
A document with no destinations carries no catalog /Names.

Tests cover the /Names //Dests //GoTo //FitH structure, the duplicate-name dedupe,
and the no-destinations path; 100% coverage, go vet and gofmt clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 0a4fa67 into main Sep 3, 2026
1 check passed
@tannevaled
tannevaled deleted the named-destinations branch September 3, 2026 19:01
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