Shawn Mervin

Tesseract.js

Open source OCR that runs in JavaScript, which I used to read text from scanned family documents.

Visit tesseract.projectnaptha.comBehind it

What it is

Tesseract.js is a JavaScript port of Tesseract, a long-running open source OCR engine. OCR, or optical character recognition, turns a picture of text into text you can search and copy. Tesseract.js compiles the engine to WebAssembly, so it runs in the browser or in Node.js with no separate program to install. It supports many languages through downloadable trained data files.

Because it runs locally, documents do not have to be sent to a third-party OCR service. The trade-off is speed and accuracy on poor scans compared with paid cloud services. Results are best on clear, flat, high-contrast images. It returns the recognised text along with confidence scores and word positions.

How I use it

  • Document uploads in my family tree app run through Tesseract.js to pull text from scanned images, and the documents are linked to family members.
  • PDFs are read with pdf-parse first, using the embedded text, with OCR as the fallback when a PDF has no text layer.
  • OCR runs in a background queue: uploads save immediately, then move through queued, processing, retrying and complete or failed.
  • Settings for language, timeout, retries and image preprocessing are configurable, with a smoke-test script to check a sample image.
  • This ran on the Docker Compose version on EC2. On the serverless relaunch, OCR is not running yet and is planned as a separate worker.

Tesseract.js is the right tool when you want OCR inside your own app without a per-page bill or sending documents elsewhere. Family records are old and personal, so keeping the reading on my own server made sense. For a small app with occasional uploads it does the job without adding a paid service.

Questions

Can you add OCR to a web app without a paid service?

Yes. I used Tesseract.js in my family tree app to read scanned images in a background queue on my own server, with pdf-parse handling PDFs that already contain text. Clear scans work best.

Tesseract.js or Amazon Textract?

Tesseract.js is free and runs locally, which suits occasional uploads and private documents. Textract is a paid AWS service with better results on forms and tables; I use it for the receipt reader on mervinc.com.

Working with Tesseract.js?

Tell me what you're building. Start a project or see the whole stack.

Got an operation that's outgrown its spreadsheets?

Tell me what your business does and where it's jamming up. If I'm not the right person for it, I'll say so and point you somewhere better.

What to send, and what happens next