Skip to content

PDF: render /Link annotations as <a> overlays (URI + internal GoTo)#591

Merged
andiwand merged 4 commits into
mainfrom
pdf-link-annotations
Jul 5, 2026
Merged

PDF: render /Link annotations as <a> overlays (URI + internal GoTo)#591
andiwand merged 4 commits into
mainfrom
pdf-link-annotations

Conversation

@andiwand

@andiwand andiwand commented Jul 5, 2026

Copy link
Copy Markdown
Member

🤖 Generated with Claude Code

Stacked on #590.

A page's /Link annotations (ISO 32000-1 12.5.6.5) now become absolutely-positioned <a> overlays.

What lands

  • /URI action → external link. href is attribute-escaped; opened in _blank (the document already sets that target).
  • /GoTo action or direct /Dest → internal #pN link; each page div gains a matching id="pN".
  • Destination resolution: a page reference (first element of a [page …] array) → its index, including named destinations via the catalog /Dests dictionary and the /Names /Dests name tree (depth-guarded).
  • /Rect is mapped through the page transform to page-box points.

Resolved entirely in the HTML layer from the parser's raw annotation dictionaries — no parser/IR change — and emitted by both the dual-layer and single-layer render paths.

Also

  • Fix: parse_page crashed (map::at) on a page with no /Contents — a blank page carrying only annotations is valid (exactly the link-only cover-page case). Guarded the lookup.
  • Refactor: elevated attribute escaping to html::escape_attribute in common.{hpp,cpp} (next to escape_text), replacing a local helper.

Tests

End-to-end PdfFile test rendering a mini-PDF with a /URI, a direct /Dest, and a named /GoTo destination — asserts the anchors and page ids in both render modes. Full non-snapshot suite (421 tests) green; real PDFs render without regression and now carry id="pN".

Deferred (noted in AGENTS.md): remote/launch actions (/GoToR, /Launch), destination scroll position/zoom (only the target page is used), and non-/Link annotation appearances.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5346eef950

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/odr/internal/html/pdf_file.cpp
Comment thread src/odr/internal/html/pdf_file.cpp Outdated
@andiwand andiwand force-pushed the pdf-metadata-file-meta branch from 1622bbc to a8c565b Compare July 5, 2026 09:23
Base automatically changed from pdf-metadata-file-meta to main July 5, 2026 09:31
@andiwand andiwand force-pushed the pdf-link-annotations branch from 5346eef to 803c25d Compare July 5, 2026 09:41
andiwand added a commit that referenced this pull request Jul 5, 2026
Address Codex review on #591:
- Reject active URI schemes (javascript:/data:/…) in /Link /URI actions;
  only navigable schemes and relative refs become live hrefs.
- Emit target="_self" on internal #pN anchors so they override the
  document's <base target="_blank"> and scroll in place.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
andiwand and others added 2 commits July 5, 2026 13:48
A page's /Link annotations (ISO 32000-1 12.5.6.5) now become absolutely
positioned <a> overlays:
- a /URI action -> external link (href attribute-escaped, opened in _blank via
  the document target);
- a /GoTo action or a direct /Dest -> internal "#pN" link; each page div gains
  a matching id="pN".

Destinations resolve a page reference (first element of a [page ...] array) to
its index, including named destinations via the catalog /Dests dictionary and
the /Names /Dests name tree (depth-guarded). The /Rect is mapped through the
page transform to page-box points. Resolved entirely in the HTML layer from the
parser's raw annotation dictionaries — no parser/IR change — and emitted by
both the dual-layer and single-layer render paths.

Also:
- Fix parse_page crashing (map::at) on a page with no /Contents — a blank page
  carrying only annotations is valid; guard the lookup.
- Elevate attribute escaping to html::escape_attribute in common.{hpp,cpp}
  (next to escape_text), replacing the local helper.

Adds an end-to-end PdfFile test rendering a mini-PDF with a /URI, a direct
/Dest, and a named /GoTo destination, asserting the anchors and page ids in
both render modes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Address Codex review on #591:
- Reject active URI schemes (javascript:/data:/…) in /Link /URI actions;
  only navigable schemes and relative refs become live hrefs.
- Emit target="_self" on internal #pN anchors so they override the
  document's <base target="_blank"> and scroll in place.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@andiwand andiwand force-pushed the pdf-link-annotations branch 2 times, most recently from 5cfa8a0 to 780d66f Compare July 5, 2026 12:49
andiwand and others added 2 commits July 5, 2026 14:54
@andiwand andiwand merged commit 4dba78b into main Jul 5, 2026
9 checks passed
@andiwand andiwand deleted the pdf-link-annotations branch July 5, 2026 12:59
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