New Tool Radar

OCR & Text Layers

How to Clean a Scan and Keep the Cleaned Page with OCRmyPDF

Use OCRmyPDF's clean-final option to remove scan artefacts from the visible page as well as the OCR input, and check nothing wanted is lost.

Schematic illustration of OCRmyPDF clean-final: the speckles go, the word harvest highlights, and the margin note must still be visible.

OCRmyPDF’s manual says –clean sends a cleaned page to OCR but does not include it in the output, while –clean-final incorporates the cleaned image in the final PDF — and warns that it might remove desired content.

Use the practice file

A practice document, practice-noisy-scan.pdf. The file is fictional.

Page Content
1 Scan with speckles and a dark edge, 10 lines, including the word “harvest”
2 Clean scan, 8 lines
3 Scan with a handwritten margin note, “see p.2”

Page 1 is the check page: the word “harvest” appears there once, among speckles.

Check clean-final

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. Run OCR with –clean

Run ocrmypdf –clean practice-noisy-scan.pdf out1.pdf.

Expected result: The output page still shows the speckles, but the text layer is clean.

2. Run OCR with –clean-final

Run ocrmypdf –clean-final practice-noisy-scan.pdf out2.pdf.

Expected result: The output page itself looks cleaner.

3. Select the word

In out2.pdf, drag across “harvest” on page 1.

Expected result: “harvest” highlights exactly.

4. Check the margin note

Look at page 3 of out2.pdf.

Expected result: The handwritten note “see p.2” is still visible — or, if it is gone, note that clean-final removed wanted content.

Verdict table

Check Expected result Pass?
Run OCR with –clean The output page still shows the speckles, but the text layer is clean. —
Run OCR with –clean-final The output page itself looks cleaner. —
Select the word “harvest” highlights exactly. —
Check the margin note The handwritten note “see p.2” is still visible — or, if it is gone, note that clean-final removed wanted content. —

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

  • Clean-final changes the visible page, so it needs a visual check, not just a text check: what it removes cannot be recovered from the output.
  • 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