New Tool Radar

AI PDF

How to Add a Searchable Text Layer to a Scanned PDF With OCRmyPDF and Check It Is Selectable

Run OCRmyPDF on a scanned PDF, then check the output text can be selected and searched.

Schematic with three steps: Confirm the PDF has no text; Run OCRmyPDF on the file; Check the text is selectable.

A scanned PDF is a picture of pages, so its words cannot be selected or searched. OCRmyPDF runs Tesseract on the pages and writes a searchable PDF with an invisible text layer behind the original page images, leaving the visible pages unchanged.

What you need

  • OCRmyPDF and Tesseract installed
  • A scanned PDF with no text layer
  • A copy of the original file, kept unchanged

Step 1: Confirm the PDF has no text

Run pdftotext on the input file; empty output is the simplest sign the PDF is only a scan and needs OCR.

Step 2: Run OCRmyPDF on the file

Run ocrmypdf with the language code and an ordinary PDF output type, for example ocrmypdf -l eng –output-type pdf input.pdf searchable.pdf, and wait for it to finish.

Step 3: Check the text is selectable

Open the output PDF, select a sentence with the mouse, and search for a word that appears on a middle page. Both must work for the text layer to count as added.

Worked example: synthetic searchable-PDF check on a 12-page scan

The table below is a synthetic example. It shows the expected result of adding a text layer; no OCR was run.

Check Before OCR After OCR
Text selectable No Yes
Search finds middle-page word No Yes
Pages look unchanged Yes Yes
Pages with text 0 of 12 12 of 12

Expected result (UNTESTED). after OCRmyPDF, all 12 pages have selectable text, a search finds a word on a middle page, and the pages still look the same. Keep the original file as well as the searchable copy. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • OCRmyPDF default output is PDF/A archival format; request an ordinary PDF with –output-type pdf when that is what you need.
  • OCR does not guarantee error-free text; inspect the output before relying on it.
  • For a JPG or PNG, Tesseract alone may be enough; OCRmyPDF is the tool for an existing scanned PDF.

Sources

See all