DEV Community

Isaac Land
Isaac Land

Posted on Originally published at enter.scholay.com

Adding Searchable Text to a Scanned Paper with OCRmyPDF

Adding Searchable Text to a Scanned Paper with OCRmyPDF

An old report has a clearly legible title that its PDF search box cannot find. Its pages are images; the viewer has no character sequence for the printed line. OCRmyPDF can use Tesseract to recognize printed material and align a searchable text layer with the page image. The result still opens as a paginated document, allowing readers to check words against the original appearance.[1][3]

Prepare the language and a separate output

OCRmyPDF uses the Mozilla Public License 2.0. Debian and Ubuntu provide system packages, macOS users can install through Homebrew, and Windows has native and Linux-subsystem routes. The current Python installation instructions require Python 3.11 or newer. The recognition engine and external dependencies follow platform-specific instructions. Ghostscript requirements depend on the processing and output path. Installing a Python package alone does not supply every external program.[2][5]

Keep the original and choose another output filename, for example ocrmypdf scan.pdf searchable.pdf. For Simplified Chinese, install the corresponding Tesseract language data and check for chi_sim with tesseract --list-langs. For a mixture of English and Chinese, specify -l chi_sim+eng. Selecting a language describes the page; it cannot supply an absent language model.[2][3][4]

Establish what each page already contains

A bound report might begin with a digitally typeset contents page and continue with photographs of archival pages. Its native text already selects cleanly. In versions with the unified mode option, --mode skip skips pages with text, and --mode redo replaces an existing OCR layer. Use --mode force deliberately because it rasterizes pages before recognizing them. First identifying the two kinds of pages protects good text already in the report.[3]

A page image aligned with an invisible searchable text layer

Figure: Image and searchable text on the same PDF page.

Use --deskew for a slight slant caused by the feeder. A page turned through ninety degrees calls for a rotation option instead. Check a page containing headings, footnotes and two columns. Inspect its orientation, search for a distinctive phrase and copy text near the column boundary. These actions test different properties. A correct search hit can coexist with reading order that jumps between columns.[1][3] Where that happens, locate the paragraph boundaries in the image and transcribe the target column in order. Record the page with the excerpt for comparison after any later recognition run.

Retain a route back to the original page

The usual archival output path is PDF/A. Add --sidecar recognized.txt if you also need the text recognized during this run. Existing text on skipped pages does not automatically enter the sidecar. Check the resulting PDF itself when searching the whole document. Return a match to its page before transcribing a quotation or recording its page number.[1][3]

Check handwriting, complex columns and tables against the page image. The Tesseract workflow discussed here targets print; its output does not reconstruct the author's paragraph and heading hierarchy. Finding a person's name establishes a character match, while nearby dates, punctuation or note numbers may still be wrong. Hand over the original PDF, the searchable version and the language selection, identifying unusually complex pages so both readers can inspect the same glyphs.[1][3]

References

  1. [1] OCRmyPDF. Introduction

  2. [2] OCRmyPDF. Installation

  3. [3] OCRmyPDF. Cookbook

  4. [4] OCRmyPDF. Installing additional language packs

  5. [5] OCRmyPDF project repository


Originally published at EnterScholar.

Scholay ยท EnterScholar

Top comments (0)