New Tool Radar

AI PDF

How to OCR Only the Scanned Pages of a Mixed PDF With OCRmyPDF Skip-Text

Run OCRmyPDF with skip-text on a PDF that mixes typed and scanned pages, then check every page has text.

Schematic with three steps: Find the pages without text; Run OCRmyPDF with skip-text; Check every page.

Many PDFs mix typed pages with scanned pages: the typed pages already have a good text layer, and re-OCRing them wastes time and can make the text worse. The –skip-text option leaves pages that already have a text layer alone and only OCRs the others.

What you need

  • OCRmyPDF and Tesseract installed
  • A PDF with some typed and some scanned pages
  • A note of which pages are scans

Step 1: Find the pages without text

Run pdftotext page by page, or check a few pages in a viewer, and list the pages that give no selectable text.

Step 2: Run OCRmyPDF with skip-text

Run ocrmypdf with the language code, an ordinary PDF output type and –skip-text, for example ocrmypdf -l eng –output-type pdf –skip-text mixed.pdf searchable.pdf.

Step 3: Check every page

Open the output and test text selection on a typed page and on a scanned page. Both must give selectable text, and the typed pages must read exactly as before.

Worked example: synthetic skip-text check on a mixed report

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

Page type Pages Text after run
Typed pages 8 Unchanged, selectable
Scanned pages 4 New text layer, selectable
Total pages with text 12 of 12 Pass

Expected result (UNTESTED). all 8 typed pages keep their original text unchanged and all 4 scanned pages gain a selectable text layer, so 12 of 12 pages have text. Use –force-ocr instead only when the existing text layer is wrong. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • –skip-text leaves pages with existing text unchanged, even if that text is wrong.
  • –force-ocr is the opposite: it OCRs every page, including ones that already have text.
  • Check a typed page as well as a scanned page; a pass on one does not prove the other.

Sources

See all