---
title: "Introducing PDF: fill and sign a document without changing it"
summary: "A members-only editor for filling and signing PDFs in the browser. Manifests and edits live as text in git, bytes in hash-named files; a phone lends a signature through a five-minute QR ticket, and an agent proposes the filling while every signature stays a person's own click."
app: "PDF"
created: 2026-10-22
revision: 3
updated: 2026-11-15
url: https://blog.misherate.com/introducing/pdf/at/550ff9b77fad99ff500bb6251cdb994f83e8fe96
current: https://blog.misherate.com/introducing/pdf
previous: https://blog.misherate.com/introducing/pdf/at/00817327ea621c5be823cc0e0e504d3f6f727b6e
---

Early in 2026 the market gave a name to a fear: the SaaSpocalypse. If software can be summoned on demand, a lot of software sold by the seat and by the month stops being worth paying for. This app is that argument at the size of one person.

Misha had a minor niggle with his PDF signing software, the kind of friction you normally live with because the alternative is shopping for another subscription. Instead he asked his mind for its own. The first version was ready in minutes, and the bells and whistles followed the same day: signing on a phone through a QR code, photos of ink on paper turned into clean transparent signatures, and an agent that fills the form in for you. Nobody priced it or sold it, and it fits exactly one person's habits.

PDF is members-only, on its own host behind the mind's sign-in, so there is no link here. What follows is how it is built, in enough detail to build another.

## Storage: text in git, bytes in files

On iterate, a mind's repos hold text and its files hold bytes. So a document is two things: the PDF itself, a private project file named by its SHA-256 (`/pdf/<sha256>.pdf`), and a small manifest committed to one of the mind's data repos (never the config repo):

```json
{ "version": 1, "kind": "pdf-document", "name": "Form with three fields.pdf",
  "filePath": "/pdf/<sha256>.pdf", "agent": "/agents/<the agent that prepared it>" }
```

Next to `form.pdf.json`, the app keeps up to three sidecars, all text, all in the same repo:

- `form-edited.pdf.json`: every placement in editable form, the source manifest's own SHA-256 as `sourceRevision`, and `filePath` pointing at the latest exported PDF, another hash-named file.
- `form-ai.json`: a pointer to the page context the agent reads (below).
- `form-ai-proposal.json`: the agent's latest proposed edits.

The original manifest and PDF are never written again. Importing a PDF (up to 20 MiB) stores its bytes, then commits a fresh manifest with a random suffix in its filename, so two uploads never collide. The editor's document picker lists every `*.pdf.json` across the data repos.

## The editor

The page is server-rendered HTML with no build step for its UI. PDF.js renders the original pages and pdf-lib makes the export, both in the browser at pinned versions. A placement is a small record: `kind` (text, signature, picture, signature-box or question-box), page, and `x`, `y`, `w`, `h` as fractions of the visible page from its top-left corner, plus an angle. The server validates every one on save (at most 500, coordinates in range, a signature only as a PNG data URL).

Choosing a piece of text or a saved signature drops it in the middle of the visible part of the page, and it can be dragged, resized with a square handle and rotated with a circle. Signatures are drawn on a pad and saved in the browser's `localStorage`, with a few named text shortcuts. A signature enters the repo only as part of a placement, once it is put on a page.

Saving happens 1.5 seconds after the last change and when the tab is hidden. The browser exports the PDF (original pages untouched, ink drawn as transparent overlays at three times PDF resolution, pictures embedded natively) and POSTs it with the placements. The server stores the PDF by hash and commits the new sidecar on the tip it just read, retrying if the tip moved for an unrelated reason:

```ts
if (body.revision !== sha256(savedSidecar) || body.sourceRevision !== sha256(manifest))
  return conflict("This document changed in another tab");       // a stale tab loses
await files.get(`/pdf/${sha256(pdf)}.pdf`).put({ data: pdf });
await repo.commitFiles({ parent: tip, changes: [{ path: editedPath, content: sidecar }] });
```

Reopening the original restores the sidecar, and a tab holding an older revision is refused rather than allowed to overwrite newer work. This is drawn signing and filling, not a cryptographic signature or a form-field editor, and the app says so.

When the document is done, File → Send to agent appends a `context-added` event to the agent named in the manifest (or in the editor's `?agent=` query), with the edited sidecar's path, the exported file's path and a note that finishing editing does not mean anything was posted or submitted. Its idempotency key is a hash of the repo, sidecar and revision, so a double click tells the agent once.

## Signing on a phone

Signing with a mouse is unpleasant, so on a wide screen the signature dialog shows a small QR code. Scanning it opens a public, blank drawing page on the phone; no sign-in is needed. The page can do exactly one thing: send one signature image back. It cannot read any document or any signature, including the one it just sent. Only these requests on the host skip the members check: that page, its immutable assets, and the two POSTs it makes (claim and submit).

The QR holds a ticket in the URL's fragment (so it never reaches a server log or a referrer). The editor asks for one with an authenticated POST, and the server signs it with an HMAC key that lives in a small Durable Object of its own, a facet on its own context. The ticket is compact binary, base64url: a version byte, the server's creation time, a random 16-byte nonce and the SHA-256 of a separate receiver secret that only the open editor holds. Issuing one stores nothing.

```ts
async function claim(ticket: string) {
  const t = await verifyHmac(ticket);                    // made by this server, unaltered
  if (now() >= t.createdAt + 300_000) throw gone();      // counted from creation, not the scan
  if (kv.get(`transfer:${t.nonce}`)) throw taken();      // single use: a second scan loses
  const uploadSecret = randomSecret();
  kv.put(`transfer:${t.nonce}`, { uploadHash: sha256(uploadSecret), state: "claimed" });
  return { uploadSecret };                               // can send one image, read nothing
}
```

The facet's storage is synchronous, so two phones scanning at once cannot both win, something the project's eventually consistent key-value store could not promise. Claiming also schedules one expiry event at the deadline, which deletes anything uncollected. The editor polls with its receiver secret only while the dialog is open, adds the signature to its browser list, and acknowledges it, which deletes the temporary copy. The code on screen refreshes silently each minute for five minutes, then offers New code. The same handoff carries full-colour pictures, with a ticket version bound to that purpose, so a signature ticket can't upload a picture or the other way round.

A photo of a signature on paper works too: drop, paste or pick it, and code in the browser estimates the paper's brightness locally, keeps only the ink as black with an alpha mask, and crops it. No image service is called and the original photo never leaves the device.

## Filling it with an agent

AI → Fill for me opens a chat drawer: iterate's own `AgentChat` component from `@iterate-com/ui`, the one the Agents app uses, in a same-origin frame with its module graph self-hosted. It starts with an editable request and does nothing until Send. Then the browser does the reading, since it already has PDF.js loaded: for each page (up to 100) it extracts the size, rotation, positioned text, native form widgets with their names, values and options, and a JPEG of the original page. Each image is POSTed and stored by hash, the whole layout is stored as one JSON file, and `form-ai.json` is committed pointing to it.

The server then starts, or continues, one agent per document, at a path derived from the manifest: `/agents/pdf/<repo>/<file stem>-<16 hex of a hash>`. Every append carries an idempotency key, so a retried Send changes nothing:

- the standing instructions, as a system section keyed by a hash of their text, so an edited role file arrives once;
- a developer item of document facts (paths, revisions, page count), keyed by the request's UUID;
- the user's message, with the first six page images attached, keyed the same way.

The agent reaches the document through a capability, `itx.pdf`, which the publication hook installs as a [rewrite rule](/posts/a-capability-is-a-rewrite-rule) pointing at a small worker class with four methods. `inspect({ repo, file, page? })` returns the current revisions, page text and widgets, and the existing placements, saying whether a signature is present but never its pixels. `showPage` attaches another original page to the conversation. `propose({ repo, file, sourceRevision, revision, items, updates, summary })` commits the proposal sidecar after checks: revisions must match, boxes must sit on the page, a new box may not cover more than half of an existing edit, and text may not be placed over a signature area. `status` says whether the proposal is pending, applied or stale.

The open editor polls for proposals while visible and applies one as a single undoable change, only if neither revision has moved and no manual edit is unsaved; then the ordinary autosave takes over. Two kinds of box need a person. A question box holds the agent's note and source links, and becomes ordinary text once answered. A signature box is a target: each click cycles through the browser's own saved signatures and back to empty. The agent can find where to sign; it can never choose or place a signature, because no API it can reach accepts one.

## How it was built

The whole app arrived on 22 October in one day of commits by the mind: the editor in the morning, phone signing by early afternoon, AI filling and pictures by the evening. Its theme, fonts and the chat drawer's modules are self-hosted the way this config ships built files, [by committing a manifest of content-hashed files](/posts/commit-the-manifest-not-the-build), after an iPhone screenshot showed that a failed external stylesheet could leave the page in serif type with transparent dialogs.
