# Tesseract.js — Pure JavaScript OCR for 100+ Languages > Run optical character recognition entirely in the browser or Node.js with no native dependencies, supporting over 100 languages via a WebAssembly port of the Tesseract engine. ## Install Save as a script file and run: # Tesseract.js — Pure JavaScript OCR for 100+ Languages ## Quick Use ```bash npm install tesseract.js # In Node.js node -e " const { createWorker } = require('tesseract.js'); (async () => { const worker = await createWorker('eng'); const { data: { text } } = await worker.recognize('image.png'); console.log(text); await worker.terminate(); })(); " ``` ## Introduction Tesseract.js brings the Tesseract OCR engine to JavaScript through WebAssembly, enabling text extraction from images directly in browsers and Node.js environments. It eliminates the need for server-side OCR services or native binary installations, making document processing accessible to any JavaScript application. ## What Tesseract.js Does - Extracts printed text from images in over 100 languages including CJK scripts - Runs entirely client-side in the browser via WebAssembly with no server round-trips - Provides word-level bounding boxes, confidence scores, and paragraph segmentation - Supports multiple workers for parallel OCR processing of batch images - Detects page orientation and script direction automatically ## Architecture Overview Tesseract.js wraps the C++ Tesseract engine compiled to WebAssembly via Emscripten. A scheduler distributes recognition tasks across web workers (browser) or worker threads (Node.js), each loading trained language data files on demand. The library exposes a Promise-based API that handles worker lifecycle, memory management, and data transfer transparently. ## Self-Hosting & Configuration - Install via npm or load from a CDN script tag for browser use - Language data files are fetched from a CDN by default; set `workerPath` and `langPath` to serve them from your own origin - Configure `tessedit_pageseg_mode` to optimize for single lines, blocks, or full pages - Use `worker.setParameters` to whitelist character sets or switch OCR engine modes (legacy vs LSTM) - Pre-load language data with `worker.loadLanguage` to avoid latency at recognition time ## Key Features - Zero native dependencies: pure JS and WASM, works in any modern browser or Node.js - Scheduler API for parallel processing across multiple workers - Incremental progress callbacks for real-time UI feedback during recognition - Supports combined language models (e.g., eng+fra) for multilingual documents - Compatible with image inputs from Canvas, File, Buffer, URL, or base64 ## Comparison with Similar Tools - **Google Cloud Vision** — cloud-hosted with higher accuracy on complex layouts, but requires API keys and per-request billing - **Paddle OCR** — Python-based with strong CJK accuracy; heavier runtime, not browser-native - **EasyOCR** — Python library with GPU support; better for server pipelines, not for client-side use - **Amazon Textract** — managed service with table and form extraction; vendor lock-in and cost at scale ## FAQ **Q: How accurate is Tesseract.js compared to cloud OCR services?** A: For clean printed text, accuracy is comparable. For complex layouts, handwriting, or low-quality scans, cloud services with custom models tend to perform better. **Q: Can it run in a web browser without a server?** A: Yes. The entire engine runs client-side via WebAssembly. Language data is fetched once and can be cached. **Q: Does it support PDF input?** A: Not directly. Convert PDF pages to images first using a library like pdf.js, then pass the images to Tesseract.js. **Q: How large are the language data files?** A: The English trained data file is roughly 4 MB (gzipped). CJK languages are larger, around 10-20 MB each. ## Sources - https://github.com/naptha/tesseract.js - https://tesseract.projectnaptha.com/ --- Source: https://tokrepo.com/en/workflows/asset-d5db39a9 Author: Script Depot