pdfkit: named destinations and GoTo links for in-document navigation - #22
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/Linkwhose/Ais aGoToaction referencing a destination name.Writecollects every page's destinations, resolves each to its page, and emits the/Names /Destsname 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./Names.Verification
Tests cover the
/Names·/Dests·/GoTo·/FitHstructure, duplicate-name deduplication, and the no-destinations path. 100% coverage,go vet,gofmtclean.Enables clickable in-document navigation in go-tex/engine (a follow-up wires
\hyperlink/\hypertarget).🤖 Generated with Claude Code