Technology

How to OCR a Scanned Document Without Sending It to the Cloud

OCR is usually a server job, which is a problem when the scans that most need it are medical records and legal exhibits. Here is how browser-based recognition works and where its limits are.

Optical character recognition is the step that turns a picture of words into actual words. Without it, a scanned contract is just an image: you cannot search it, copy from it, or feed it into anything else.

It is also the most computationally expensive thing most people ever do to a document, which is why it has traditionally been a server job. That creates an awkward situation, because the documents that most need OCR are frequently the ones least appropriate to upload.

The documents that need OCR most

Think about what actually arrives as a scan rather than a text file: medical records, court exhibits, historical case files, signed agreements, tax paperwork, identity documents, and archive material.

Almost every item on that list is confidential. Sending them to a cloud OCR API means handing exactly the material you are most careful about to a third-party processor, usually to solve a fairly mundane searchability problem.

Recognition in the browser

Tesseract, the most widely used open-source OCR engine, has been compiled to WebAssembly. That means the recognition pass can run inside your browser's sandbox, on your own processor, with the image never leaving your machine.

PDF Vault uses this approach. You load the scan, select the document's language, and the recogniser produces text you can copy, export, or keep as a searchable layer. The first run downloads the language model; after that it works with no connection at all.

What accuracy to expect

On a clean 300 DPI scan of printed text, browser-based Tesseract is highly accurate and broadly comparable to server engines — they are frequently running the same underlying model.

Accuracy falls off with the same factors that affect any OCR engine:

  • Low resolution. Below about 200 DPI, character shapes become ambiguous.
  • Skew. Pages photographed at an angle recognise poorly. Straighten first.
  • Unusual fonts. Decorative and script typefaces are much harder than standard serif or sans-serif text.
  • Poor contrast. Faded photocopies and coloured backgrounds both hurt.
  • Handwriting. Tesseract is built for printed text. Do not rely on it for handwriting.

Selecting the correct language before the run makes a material difference, because the engine uses language-specific character and word models.

The honest tradeoff

Local OCR is slower than server OCR. A datacentre GPU will beat your laptop's CPU, and on a large batch that difference is measured in minutes rather than seconds.

What you get for that time is that the medical record never left your machine. For a hundred-page batch of sensitive scans, most people find that a straightforward trade. For a ten-thousand-page archive of public documents, it probably is not, and you should use a server tool.

A practical workflow

Photograph or scan at 300 DPI if you can control it. Convert images to a PDF first if you have loose files. Run OCR with the correct language selected. Then check a few pages of the output — OCR quality varies with source quality, and it is better to discover that immediately than after you have relied on a search that silently missed something.

Keep reading