AntiUpload// files stay on your deviceENSESSION · 000RLB
← All articles
Engineering

How we built true PDF text editing in the browser (and what Adobe still does better)

Most free “edit PDF text” tools don't edit PDF text. They draw a white box over the old text and type new text on top — the original stays in the file underneath, recoverable by anyone who looks. We spent a week building the real thing for our Edit PDF Text tool: the original string is genuinely removed from the file, the replacement uses the document's own font, whole paragraphs re-wrap like a word processor — and it all runs in your browser, with the document never leaving your device. Here's how it works, the bug our own tests caught, and what Adobe still does better.

Why “editing PDF text” is hard

A PDF isn't a document the way a Word file is. It's a drawing program: a page is a stream of instructions like “move the pen to (72, 700), select font F1 at 14 points, draw the string ‘Amount due: 500 dollars’”. There are no paragraphs, no sentences — often not even whole words. One visual line is frequently drawn as five or six separate fragments with hand-tuned spacing between them.

Worse, the fonts inside a PDF are usually subsets: the file only carries the letters the document actually used. If the invoice never contained a “Z”, there is no Z in the embedded font. That's why so many tools give up and paint over the text instead — and why the ones that don't (Adobe Acrobat, a couple of upload-based services) charge for it.

What our editor actually does

When you retype a line, the engine:

  • decodes and tokenizes the page's raw instruction stream, byte-for-byte losslessly — everything we don't deliberately change survives exactly;
  • walks every text-positioning instruction (including nested transforms) to find the exact draw calls that produced the line you clicked — all of them, since one line is many fragments;
  • re-encodes your replacement in the document's own font. For simple fonts that's a character-map check; for the CID-keyed fonts modern exporters produce, we invert the font's ToUnicode table — which means a character is available exactly when it already appears somewhere in the document in that font;
  • splices the new string into the stream and rebuilds the page — overwriting the original content object in place.

When the font can'tspell your replacement (you typed a Z and the subset has no Z), we don't fake a glyph and we don't silently fail: the engine embeds a metric-matched standard font and still performs a true replacement — the old text leaves the file; only the typeface changes. The result screen tells you exactly which method each edit got. Honest reporting over silent degradation is the rule everywhere on this site.

The bug our own test caught

Our first version passed every unit test and still had a privacy hole. When we rebuilt a page's instruction stream, we registered it as a new object in the file and pointed the page at it. The page rendered perfectly — but the originalstream, with the pre-edit text, was still sitting in the file as an orphaned object. Invisible on screen, recoverable from the bytes. That's the same class of leak that makes bad redaction tools dangerous, and we'd already built Redact PDF specifically to avoid it.

The fix: overwrite the original stream object in place, so the old bytes physically leave the file. Our test suite now asserts that the pre-edit text is absent from the raw saved bytes— not just from what renders. If you're evaluating any PDF editor, that's a test worth running yourself: edit a document, open the output in a text editor, and search for what you replaced.

Paragraph reflow — the Acrobat feature

Editing one line is corrections-grade. What makes Acrobat feel like a word processor is clicking into a paragraph and typing while the text re-wraps. We built that too: the editor detects paragraph blocks (uniform line spacing, aligned edges), you rewrite the whole paragraph in a text box, and the engine re-wraps your words to the paragraph's width — emitting each new line at the original spacing, then restoring the position state so nothing else on the page moves.

Where a paragraph can't be safely reflowed in place — rotated text, mixed fonts mid-block — the engine refuses with a plain-language reason and falls back to covering the block and redrawing it wrapped in a matched font. A rewrite always lands one way or the other, and the tool tells you which happened.

Editing scanned documents

A scan has no text at all — it's a photograph. For those pages the tool offers one-click OCR (the same in-browser engine we benchmarked publicly), which makes the recognized lines editable. A correction on a scan is necessarily a patch on the image — but instead of a white box, we sample the actual background color around the line (scans are rarely white) and match it. In our tests on a tinted scan, the patch color came out pixel-identical to the paper. The corrected text also becomes real, selectable text in the output.

Does it break on real files?

We ran the engine over a 55-document corpus: arXiv papers, IRS tax forms, and the pypdf project's collection of deliberately awkward PDFs (Arabic text, rotated pages, inline images, CMYK, damaged metadata). Across 111 pages and 14,497 text-drawing instructions, the tokenizer round-tripped every stream with positions identical to a hundredth of a point, all 48 live edit attempts succeeded, and every output rendered cleanly. One file was too damaged to parse at all — the tool tells you that up front instead of producing garbage.

What Adobe still does better

Honesty section. Three things Acrobat has that we don't:

  • Glyph synthesis.Acrobat can type characters the embedded subset never contained, in a face that matches almost perfectly, because Adobe ships a licensed font library and sophisticated font-matching. In a browser, with only the subset in the file, that's not honestly achievable — our matched-font fallback is the truthful approximation, and we label it.
  • Reflow across blocks. Our reflow works within a paragraph. Acrobat can push content below a paragraph down when it grows. We tell you instead: content below is not moved.
  • Object manipulation. Moving images, reshaping layout regions — Acrobat is a full page editor. We edit text.

What we have that Acrobat's web editor doesn't: your document never leaves your machine, and it's free. Acrobat's web version uploads your file to Adobe's cloud and costs around $20/month. For a contract, a lease, an invoice, a medical letter — the documents people actually edit — we think the trade is clear.

Try it: Edit PDF Text. If you find a document it mishandles, we genuinely want it — that's how the corpus above got built.

Browse the tools →Every tool runs in your browser. 0 bytes uploaded · ever.