for agents/llms.txtv0.14.16

Home / Articles / An augmented PDF viewer: how hard is it to build one in the browser that renders any PDF and opens the provenance, the graph and the comments behind it? Less than I thought

An augmented PDF viewer: how hard is it to build one in the browser that renders any PDF and opens the provenance, the graph and the comments behind it? Less than I thought

By · 2026-10-31 · article v1.0.0 · newsroom v0.14.16 · pdfbookreadingprovenanceopen-sourcejavascriptresearchbriefarticle

Abstract: The augmented book made me ask a question about PDF. It is a strange format: static, closed, made for a printed page, with nothing behind it. But a PDF is how most serious documents still travel, and the book will have one. So why not augment the PDF? I asked a research agent how feasible it would be to build a viewer in JavaScript, in the browser, that renders any PDF normally but also shows a layer the PDF cannot: the provenance of each claim, the nodes of the semantic graph, definitions, comments and review cards, on demand, beside the text. The answer is that most of it exists, as open source we can extend. Mozilla's PDF.js, under the Apache licence and committed to the day before we looked, already draws a page as a stack of layers, canvas, text and annotations, and announces each one as it renders, so a layer of our own fits on top. It can read a PDF's attachments, its metadata, its links and its fingerprint. And the augmented layer does not need to live in the PDF at all: the PDF only needs clues to find it, an attached file, an id in its metadata, a link, the file's own identifier, or a QR code that survives printing. Hypothesis already anchors annotations to PDFs this way, and e-invoices already carry machine-readable data inside human-readable PDFs. The hard part is not the PDF. It is the interface, anchoring claims to text reliably, and making sure the layer a viewer loads is signed by the people who made the document.

The proposed stack: PDF.js draws the page in layers, and one more layer of ours carries what the PDF cannot.

In short

Why augment a PDF

In the augmented book I argued that a book should be one source in layers, and that print should carry a QR code where a layer would open. That made me look at PDF differently. A PDF is a strange format: it describes a printed page, it is static, it has nothing behind it, and every reader shows it the same way. But it is also how books, papers, reports and contracts actually travel, and the book of The Ultimate Insider has two of them, the book and its review companion.

So the question is simple. If we have the layers anyway, why can't a PDF have them? Not by inventing a new format nobody can open, but with a viewer that renders any PDF normally and, when the PDF carries the right clues, shows everything behind it.

A viewer that already exists

The research agent cloned the main open-source projects and read their code. The one to build on is PDF.js, Mozilla's PDF renderer, the one inside Firefox:

There are alternatives. EmbedPDF builds a viewer on Chrome's PDF engine compiled to WebAssembly; its licence differs between packages and needs checking. MuPDF.js is excellent and licensed under the AGPL, which would oblige us to publish our changes or buy a licence. For writing PDFs, pdf-lib can attach files and add metadata, but has not been updated since 2021; two maintained forks carry it on. And the commercial viewers, Nutrient, Apryse and Adobe's embed API, sell overlays and annotation layers, which tells us there is a market for this.

The PDF only needs clues

Five clues, tried in order, for finding a PDF's augmented layer, and which one survives what.

The insight in the memo is that the augmented layer probably does not need to be in the PDF at all. The PDF just needs enough clues for the viewer to find it. There are five, and the viewer tries them in order:

  1. An embedded file. A PDF can carry attachments, and PDF 2.0 can mark one as data associated with the document. We attach the layer as JSON. It is the strongest clue, and the most fragile: printing to PDF, email gateways and compressors often strip attachments.
  2. Metadata. A PDF's XMP metadata can hold our own fields, such as the document's id and the address of its layer.
  3. A link. An ordinary link in the PDF to the document's page on our site, which every reader can follow too.
  4. The file's own identifier. PDFs carry an id in their trailer, which PDF.js turns into a fingerprint; the viewer can look it up on our server. It is weak on its own: it is optional, copies share it, and regenerating the file changes it.
  5. A QR code on the page, read from the rendered image in the browser, or by a phone from a printed copy. It survives printing, which nothing else does.

It has been done, in parts

What not to do: JavaScript inside the PDF

PDF has its own JavaScript, which Acrobat runs: it can calculate forms, open dialogs and reach the network. It is also one of the most attacked parts of PDF. Search results for this research reported an Acrobat JavaScript flaw exploited from late 2025 and patched in April 2026, and PDF.js itself had a flaw in 2024 that let malicious font data run code, fixed in version 4.2.67. Many viewers ignore PDF JavaScript or run it in a sandbox, and security teams turn it off. The augmented layer must never depend on it: the PDF carries clues, and our viewer does the work.

How hard is it?

Less than I thought. A minimum version is:

  1. PDF.js's viewer component, with one extra layer drawn when each page's text is ready.
  2. Discovery through the five clues, in order.
  3. Anchors: each claim in the layer points at a quote of the text and a page, matched against the text PDF.js extracts, the way Hypothesis does; named destinations can be firmer anchors for our own PDFs.
  4. Writing the clues when we build the book's PDF: attach the JSON, set the metadata, add the link and stamp the QR code.
  5. Signing: the layer is signed with the publisher's key, and the viewer checks it before showing anything.

The research agent's estimate is weeks for a prototype, with the work in the interface and the data, not in the PDF. That matches what we already have: the book's claims, sources, graph and review cards exist as files, and the newsroom's site already shows sections at more or less detail.

The risks

What I want to try

Take the RC1 PDF of the book, attach its claims, sources and graph as a signed layer, add its id to the metadata and a QR code to a few pages, and open it in a PDF.js viewer with one extra layer. Then put the same viewer inside the iPad app, where the review comments go on the page. The PDF still opens in Preview, in Acrobat and in a browser, exactly as before; it just has more behind it in ours.

What this does not claim

Where this comes from

Peer review Not reviewed yet. Review it

Threads

Site & engineeringGraphs & knowledge This article as a graph →

Builds on

All articles · All graphs

Article No. 338 · start a reading list with it

Want the next issue by email. One issue a week or so: what was published, what it adds up to, and what is worth your time. Subscribe to the SGit Newsroom →

← All articles

Reviews

Reviews on the record, by agents, the editor and the desk, against the criteria. Each is kept for good and answered finding by finding. All reviews →

No reviews yet.