How OCR Works: Extract Text from Scanned PDFs
When a paper contract, historical book, or printed invoice is digitized through an office scanner or smartphone camera, the resulting PDF is simply a grid of colored pixels. You cannot search for names using Ctrl+F, copy sentences into Word, or use screen readers. Optical Character Recognition (OCR) solves this by translating visual shapes into machine-encoded text.
What is Optical Character Recognition (OCR)?
Optical Character Recognition is a computer vision technology that converts images of typed, handwritten, or printed text into editable, searchable machine data (such as ASCII or Unicode text characters).
Modern OCR engines (such as Google’s open-source Tesseract engine, which powers FileTools in-browser OCR via WebAssembly) do not simply match letters against static font templates. Instead, they use neural network feature extraction and line-finding algorithms to detect word baselines, segment character strokes, and evaluate lexical language models to predict the most probable word matches.
| OCR Processing Stage | What Happens Under the Hood | Why It Matters for Accuracy |
|---|---|---|
| 1. Image De-skew & Orientation | Detects page tilt angle and rotates image upright | Text recognition models expect straight horizontal baselines. |
| 2. Adaptive Binarization | Converts grayscale pixels into pure black & white (Otsu thresholding) | Removes paper shadows, yellowing, and coffee stains. |
| 3. Line & Word Segmentation | Isolates text blocks, paragraph boundaries, and spacing | Distinguishes between separate columns and paragraph margins. |
| 4. Neural Character Classification | Evaluates stroke contours against trained linguistic datasets | Accurately recognizes letters across various font typographies. |
| 5. Invisible Text Layer Injection | Places recognized text behind original scanned imagery | Produces searchable PDFs that preserve exact original visual layout. |
Adaptive Binarization: Otsu vs Sauvola Thresholding
Before character strokes can be identified, color or grayscale scanned pixels must be converted into binary (pure black text on pure white background). How this binarization occurs determines whether text is preserved or obliterated.
• Global Otsu Thresholding calculates a single luminosity cutoff for the entire page. While fast, if a document has uneven lighting (e.g. a phone shadow in the corner), dark areas turn into solid black blobs while light areas drop out completely.
• Local Adaptive Sauvola Thresholding calculates dynamic local means across rolling pixel windows (typically 15×15 to 30×30 pixels). It effectively isolates character strokes from background yellowing, watermarks, coffee stains, and uneven smartphone camera lighting.
How to Maximize OCR Accuracy: Scan Preparation & Resolution Math
The accuracy of OCR is governed by mathematical optical constraints. Follow these precision guidelines:
1. Target 300 DPI Resolution (x-Height Rule): Neural character classifiers require lowercase letters (such as "e", "x", "o") to have an x-height of at least 20 to 30 pixels. At 72 DPI, an 8pt footnote font has an x-height of only 4 pixels, making recognition impossible. At 300 DPI, the same letter has 24 pixels, ensuring over 99% character confidence.
2. De-Skew Within ±1.5 Degrees: Text line finders track horizontal baselines. A page skew exceeding 2 degrees disrupts inter-word bounding boxes, dropping recognition accuracy by up to 15–20%. Always straighten pages before running OCR.
3. Ensure Even Illumination: Avoid harsh overhead shadows. Shadows distort adaptive binarization windows, leading to broken character loops (turning "e" into "c" or "d" into "cl").
4. Select the Correct Primary Language Dictionary: OCR engines combine visual stroke classification with trie-based lexical language models. Selecting the correct language dictionary resolves ambiguous letter pairs like "rn" versus "m".
FileTools OCR does not destroy or overwrite your original scan. Instead, it generates a "Searchable PDF" (PDF Sandwich) by placing an invisible, selectable text layer with 0% opacity directly above the corresponding words in your scan. You retain the exact archival look of the paper original while gaining complete Ctrl+F searchability.
Page Segmentation Modes (PSM): Navigating Multi-Column Layouts
Scanned documents rarely consist of a single continuous block of text. Newspapers, magazines, academic papers, and invoices contain complex layouts with columns, sidebars, tables, and headers.
OCR engines use Page Segmentation Modes (PSM) to detect structural boundaries. If a two-column legal contract is analyzed under a single-block assumption, the engine reads horizontally across both columns, merging unrelated clauses into incoherent sentences. Advanced page layout analysis segments columns vertically first before tracking individual line baselines.
Current Technical Limitations of In-Browser OCR
While in-browser WebAssembly OCR is remarkably convenient and private, it has realistic technical limitations:
• Cursive & Unstructured Handwriting: While OCR excels at printed typography and computer fonts, handwritten doctor notes, cursive signatures, and informal script often yield low confidence scores.
• Complex Multi-Column Tabular Data: Highly nested financial tables without clear borders can occasionally be merged horizontally during plain text extraction. Review extracted tables carefully.
• Device Memory Constraints: Because OCR runs entirely inside your browser tab without cloud supercomputers, processing 100-page scanned documents simultaneously can take several minutes. For optimal speed, process scanned files in batches of 10 to 25 pages.
Common Mistakes to Avoid
- ✕ Running OCR on an upside-down or sideways scan, causing the engine to interpret letters as meaningless gibberish.
- ✕ Attempting to OCR heavily blurred photographs taken in low-light conditions with motion blur.
- ✕ Assuming OCR automatically fixes misspelled words present in the original printed source document.
Frequently Asked Questions
Are my confidential scanned documents uploaded to any OCR cloud server?
No. FileTools uses compiled WebAssembly (Tesseract.js) running directly on your computer. Your document stays in your local browser memory.
Can I copy the recognized text into Microsoft Word or Google Docs?
Yes. Once OCR processing completes, you can either copy the plain recognized text directly or download the searchable PDF.
What is the ideal DPI resolution for running OCR on scanned documents?
A resolution of 300 DPI is the industry sweet spot for optical character recognition. Scans below 200 DPI suffer character confusion (such as "c" vs "e"), while scans over 400 DPI increase processing overhead without noticeable accuracy gains.
Does OCR work on non-English foreign languages and multi-lingual files?
Yes. In-browser OCR models support Latin, Cyrillic, Devanagari, and Asian scripts when the corresponding trained language dictionary is loaded, enabling accurate character segmentation and contextual lexical validation.
What is a Searchable PDF or PDF Sandwich?
A Searchable PDF retains the original high-resolution scanned page image in the foreground while placing an invisible, selectable text layer behind it at matching coordinates, allowing full text selection and Ctrl+F searching.
Try the Related Free FileTools
Put these concepts into practice instantly. All tools run 100% locally in your browser with complete privacy.
Related Educational Guides
How to Compress a PDF Without Losing Quality →
Learn why PDF files become huge, how image downsampling and JPEG quantization work, and how to reduce file sizes safely without degrading document readability.
Image GuidesJPG vs PNG vs WebP: Which Image Format to Use? →
A practical, engineering-based comparison of modern raster image formats. Discover when to use JPEG, PNG, or WebP for websites, print, and transparency.
About the Author: Shaik Imranpasha
Independent software developer and creator of FileTools. Focused on building browser-based productivity tools, client-side WebAssembly file processing, and privacy-first web utilities.