New Tool Radar

OCR & Text Layers

How to Replace an Old OCR Text Layer with OCRmyPDF

Use OCRmyPDF's redo-ocr mode to replace a bad old text layer without touching the visible text, and check the new layer is better.

Schematic illustration of OCRmyPDF redo-ocr: the old layer stores harvset, the new layer stores harvest and the total 42 is found.

OCRmyPDF’s manual says –redo-ocr detects and removes the hidden OCR layer from files previously OCRed, then applies OCR to the raster images, while existing visible text objects are not changed.

Use the practice file

A practice document, practice-old-ocr.pdf. The file is fictional.

Page Content
1 Scanned page with a bad old layer: the word “harvest” is stored as “harvset”
2 Scanned page with a bad old layer: the total “42” is stored as “4Z”
3 Born-digital text page, correct

Page 1 is the check page: the visible word is “harvest” but the old layer stores “harvset”.

Check redo-ocr

Expected result. We checked the OCRmyPDF manual and the Tesseract manual. We did not run any tool. The checks below are what to expect if the work is done correctly; run them yourself on the practice file.

1. Prove the old layer is bad

Use Find for “harvest” in the original.

Expected result: 0 hits, because the layer stores “harvset”.

2. Run OCR with –redo-ocr

Run ocrmypdf –redo-ocr practice-old-ocr.pdf out.pdf.

Expected result: OCRmyPDF replaces the old layer.

3. Search again

Use Find for “harvest” in out.pdf.

Expected result: 1 hit, on page 1.

4. Check the total

Use Find for “42” in out.pdf.

Expected result: 1 hit, on page 2, and the visible text on page 3 is unchanged.

Verdict table

Check Expected result Pass?
Prove the old layer is bad 0 hits, because the layer stores “harvset”. —
Run OCR with –redo-ocr OCRmyPDF replaces the old layer. —
Search again 1 hit, on page 1. —
Check the total 1 hit, on page 2, and the visible text on page 3 is unchanged. —

Related guides: How to Batch OCR a Multi-Page PDF with Consistent Settings — How to Add a Searchable Text Layer to a Scanned PDF.

Limits

  • Redo-ocr is for a bad invisible layer, not for bad visible text: if the page image itself is wrong, no OCR mode can fix it.
  • Command-line OCR rewrites the file, so always work on a copy and keep the original scan untouched.
  • UNTESTED — no OCR tool was run; all results above are expected results. The practice file is fictional.

Sources

See all