Skip to content

Add clickable link support (annotations + text-detected URLs)#9

Merged
kdroidFilter merged 1 commit into
masterfrom
feat/link-support
Jul 12, 2026
Merged

Add clickable link support (annotations + text-detected URLs)#9
kdroidFilter merged 1 commit into
masterfrom
feat/link-support

Conversation

@kdroidFilter

Copy link
Copy Markdown
Collaborator

Closes #8

Summary

  • New common API: PdfLink / PageLinks (bounds in PDF points, uri, destPageIndex), PdfDocument.pageLinks() and public PdfReaderState.pageLinks(pageIndex).
  • Links come from two PDFium sources, merged with overlap dedup (annotation wins over a text-detected link under the same rect):
    • link annotations via FPDFLink_Enumerate — URI actions and internal GoTo destinations
    • web links via FPDFLink_LoadWebLinks — URLs and e-mail addresses detected in the page text (PDFium returns e-mails as mailto: URIs)
  • PdfPage gains linksEnabled: Boolean = true and onLinkClick: ((PdfLink) -> Boolean)?: an invisible clickable overlay per link rect, hand cursor on desktop, click semantics for accessibility, and correct touch-scroll interplay. External URIs open through LocalUriHandler; onLinkClick returning true consumes the click.
  • PdfReader scrolls to the destination page for internal GoTo links and exposes the same linksEnabled / onLinkClick knobs.
  • Implemented on all five backends:
    • JVM + Android: nCountPageLinks / nExtractPageLinks in the shared pdfium_jni.cpp; JVM degrades to empty links if a prebuilt native predates the API
    • iOS: cinterop (fpdf_doc.h / fpdf_text.h already exposed by the .def)
    • JS / wasmJs: new links op in pdfium_worker.mjs (the shipped pdfium.wasm already exports FPDFLink_*)
  • Example app: internal links jump via jumpToPage; README documents the feature.

Test plan

  • smokeTest against a 2-page PDF containing all four link kinds — URI annotation, internal GoTo (dest=1), text-detected URL, text-detected e-mail (mailto:) — all extracted correctly
  • Compiles: JVM, JS, wasmJs, Android Kotlin + NDK/CMake, Linux JNI glue, example app
  • iOS compile on macOS CI (cinterop code follows the file's existing patterns; cannot build on Linux)
  • Rebuild prebuilt JNI glue for macOS/Windows hosts (buildJniMacOs / buildJniWindows) before publishing
  • Manual click-through on desktop/web: external link opens browser, e-mail opens mail client, GoTo scrolls the reader

Extract link annotations (URI + internal GoTo) via FPDFLink_Enumerate and
auto-detected web links (FPDFLink_LoadWebLinks, e-mails as mailto:) on all
five backends (JVM/Android JNI, iOS cinterop, JS/wasmJs worker). PdfPage
gains a clickable link overlay (hand cursor, accessibility semantics);
external URIs open via LocalUriHandler, internal GoTo links scroll PdfReader
to the destination page, and onLinkClick allows interception.
@kdroidFilter kdroidFilter merged commit d300b83 into master Jul 12, 2026
12 checks passed
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.

Link support planned?

1 participant