Skip to content

pdfkit: add Page.AddLink for clickable /Link URI annotations - #21

Merged
tannevaled merged 1 commit into
mainfrom
link-annotations
Sep 3, 2026
Merged

pdfkit: add Page.AddLink for clickable /Link URI annotations#21
tannevaled merged 1 commit into
mainfrom
link-annotations

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

What

A generated PDF could draw a hyperref link's text but not make it navigable — there was no annotation API — so \href/\url rendered as plain text in the PDF even though the SVG output already carried a live <a href>.

How

Page.AddLink(rect Rect, uri string) records a borderless clickable rectangle whose /A is a URI action; Write emits one /Link annotation per link in the page's /Annots array. /Rect is [llx lly urx ury] in the page's default user space — the same coordinates the drawing methods use — and a page with no links emits no /Annots.

Verification

Tests cover the emitted /Annots·/Link·/URI structure and paren escaping in the URL, plus the no-links path. 100% coverage, go vet, gofmt clean.

Enables clickable PDF links in go-tex/engine (a follow-up wires the engine's PDF driver's link node to this API).

🤖 Generated with Claude Code

A generated PDF could draw a hyperref link's text but not make it navigable —
there was no annotation API — so \href/\url rendered as plain text in the PDF
while the SVG output already carried a live <a href>.

Add Page.AddLink(rect, uri): it records a borderless clickable rectangle whose /A
is a URI action, and Write emits one /Link annotation per link in the page's
/Annots array (/Rect is [llx lly urx ury] in default user space, matching the
coordinates the drawing methods use). A page with no links emits no /Annots.

Tests cover the emitted /Annots //Link //URI structure and paren escaping in the
URL, plus the no-links path; 100% coverage, go vet and gofmt clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 3cd5a7d into main Sep 3, 2026
1 check passed
@tannevaled
tannevaled deleted the link-annotations branch September 3, 2026 16:21
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