How OnePDF works: a PDF engine in your browser

Why not a server

The usual way to build a PDF website is to do the work on a server: receive the file, process it, send it back. It is simpler to build, and it means holding every user's documents, however briefly. OnePDF was built the other way round. The program that reads, edits and writes PDFs runs in your browser, so the documents never need to leave your device, and a tool keeps working once the page has loaded, connection or not.

One engine for the phone and the web

OnePDF's engine is a library written in Rust. It covers the format itself: reading files, including damaged ones; text extraction and layout; the editable canvas behind Edit PDF; annotations, forms, encryption, digital signatures, redaction, optimisation and page operations; and rendering pages to pixels.

The phone app and the website run the same code. For the web it is compiled to WebAssembly, and the browser gets exactly the functions the phone does, generated from the same definitions, so a fix in the engine reaches both. It runs in a worker of its own, so drawing and saving never freeze the page.

Reading is not editing

A PDF can hold far more than any editor models: colour profiles, digital signatures, structures other programs added. Rewriting a file from the editor's understanding of it would quietly drop whatever the editor did not understand. So the engine keeps the original bytes beside its model: an unchanged file is handed back exactly as it arrived, and an edit is written as an addition to the file rather than a rebuild of it.

Redaction is a deliberate exception. There, keeping the earlier version would keep what you removed, so the redacted file is rebuilt from scratch.

Editing text in the document's own fonts

A PDF has no paragraphs, only runs of letters drawn at positions. The engine groups them back into paragraphs, and when you retype one, sets the new words in the font the document embedded, with its weight, slant, spacing and underline.

Embedded fonts usually hold only the letters the document used. When you type one they lack, such as an accented name or a currency sign, the engine sets it in one face that has every missing letter: the standard face resembling the document's own if it can, otherwise an open Noto face, which the browser downloads only when a letter first needs it.

Text recognition on your device

For scans, OnePDF uses PaddleOCR's PP-OCRv6 networks, which read about 50 languages, among them Chinese, English, Japanese and dozens of Latin-script languages, with one model, and are published as open ONNX files. They run in the browser with ONNX Runtime Web, on the graphics card in Chrome and Edge on a computer and on the processor's cores everywhere else.

Everything around the networks, from finding lines of text to splitting them into words and putting right-to-left text in reading order, is Rust compiled to WebAssembly as well. The models are downloaded once, checked against known checksums and cached, and the recognised words are added to the page through the same engine that edits it.

Fast after the first visit

Every page of this site arrives already drawn, so it reads before any script has run, and the engine downloads only when you open a file. A service worker keeps the app on your device afterwards, so it opens at once, and opens with no network at all.

Tools in this guide