Skip to content

fix(pdf): select text and follow links, such as the table of contents, in the PDF viewer - #188

Merged
lorenzocorallo merged 1 commit into
mainfrom
lorenzocorallo/fix-pdf-text-and-toc
Nov 25, 2026
Merged

lorenzocorallo merged 1 commit into
mainfrom
lorenzocorallo/fix-pdf-text-and-toc

Conversation

@lorenzocorallo

Copy link
Copy Markdown
Member

Problem

The shared pdf.js viewer (PdfViewer, used by PdfDialog in Regolamenti, the editor preview, Soci receipts and eSign) drew each page as a canvas only:

  • the text could not be selected or copied;
  • links did nothing, so clicking an entry in a document's table of contents (indice) did not go to its page.

Fix

  • Text layer: each page gets pdf.js's TextLayer, with transparent text over the canvas, so text can be selected and copied. The CSS is a trimmed copy of pdf.js's .textLayer rules, in .pn-text-layer in src/styles.css. The selection colour is the brand blue.
  • Links: the page's Link annotations are parsed with zod at the pdf.js boundary.
    • A link to a point in the document (named or explicit destination: XYZ, FitH, FitBH, FitR) is a button labelled "Vai alla pagina N" / "Go to page N". It scrolls the viewer so the destination sits at the top.
    • A web link opens in a new tab with rel="noopener noreferrer". pdf.js only passes on URLs with a safe scheme.
  • eSign placement is unchanged: while the cursor is a crosshair (placing a signature box), the overlay still takes every click on the page. Otherwise the overlay lets the pointer through to the text and links, and only the boxes on it take clicks. All onPageClick handlers already do nothing outside placement.
  • While you drag to select text, links let the pointer through. This works the same way as in pdf.js's own viewer, using selecting and endOfContent.

Verification

I tested in agent mode by opening PdfDialog on a test PDF with a table of contents (5 internal links and 1 web link), driven over CDP in headless Chromium:

  • Six links were found, with the labels "Vai alla pagina 2…6" and the web URL.
  • Dragging over the title selected "Regolamento di prova\nIndice", and the selection was highlighted.
  • Clicking "Articolo 3" scrolled to page 4, and the counter showed "Pagina 4 di 6" with the heading at the top.

pnpm check (0 errors), pnpm typecheck, pnpm test (259 passed) and pnpm build all pass.

…, in the PDF viewer

The viewer drew each page on a canvas only, so its text could not be selected and the links in a document did
nothing. Each page now carries pdf.js's text layer, transparent over the drawing, and its link annotations: one to a
point of the document (a table of contents entry) scrolls the viewer there, one to a web address opens in a new tab.
While a crosshair places a signature box, a click on a page still goes to the placement.
@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 35 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 66d2ca91-0769-45e3-947f-c6a142d3fdf5
Commits

Reviewing files that changed from the base of the PR and between 5b8f622 and f011193.

Files selected for processing: 2

  • src/features/esign/pdf-viewer.tsx
  • src/styles.css
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@lorenzocorallo
lorenzocorallo merged commit e9deb47 into main Nov 25, 2026
2 checks passed
@lorenzocorallo
lorenzocorallo deleted the lorenzocorallo/fix-pdf-text-and-toc branch November 25, 2026 17:50
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