Tools,

Enhance a scanned PDF

99.9%

of our aged scan paper came out white

Get clean_scan.py

Yellow paper, gray scans, shadows, show-through. One free command.

One command, then OCR for search

python3 -m venv clean-venv
. clean-venv/bin/activate
pip install numpy pillow
python3 clean_scan.py scan.pdf scan-clean.pdf
ocrmypdf scan-clean.pdf scan-clean-ocr.pdf

It divides each page by a blurred copy of itself. Slow changes in the paper go white, and the text stays. clean_scan.py, MIT license.

It writes gray pages. To keep colored ink and stamps, add --color. It needs poppler, and the last line needs OCRmyPDF: brew install ocrmypdf poppler on a Mac.

python3 clean_scan.py scan.pdf scan-color.pdf --color

White paper on every kind we tried

Blank paper at gray 230 or lighter, simulated scans of made-up pages
Kind As scanned clean_scan.py
Yellowed paper 23.8% 100.0%
Gray, dark scan 0.0% 100.0%
Shadow at one edge 50.8% 100.0%
4 new kinds, script frozen 0.6% 100.0%
The top of a real book page on tan paper: on the left as scanned, brown and dim, on the right after clean_scan.py, white paper and black text
A real public domain book page: as scanned, then clean_scan.py.

Other ways, and what they broke

6 fully aged pages: yellow paper, show-through, specks, a shadow. 966 words.
Way Paper white Tesseract words
As scanned 2.3% 721, 472 false
OCRmyPDF --clean-final 2.2% 603, 501 false
magick -level 20%,80% 85.9% 904, 136 false
magick -lat 50x50-5% 98.8% 896, 813 false
magick +dither -colors 8 5.0% 639, 621 false
clean_scan.py 99.9% 943, 22 false
Part of an aged made-up form, three times: as scanned on yellow paper with faint mirrored text, after magick -lat with the mirrored text turned black, and after clean_scan.py with white paper, dark text and no mirrored text
Top: as scanned. Middle: -lat. Bottom: clean_scan.py.

OCR gains only on bad pages

Other readers on the 6 fully aged pages, 966 words
Reader As scanned clean_scan.py
Apple Vision 961, 119 false 962, 5 false
Our Actor's code, build 0.1.102 842, 294 false 947, 18 false
OCRmyPDF, the commands above 687, 421 false 949, 14 false

On 10 real book pages, the words barely changed: OCRmyPDF found 1,932 and 1,931 of 1,955. Clean those for the eye, not for search.

Where it can hurt

Check the first pages before you run a whole book.

Smaller files on our scans

PDF size
File As scanned clean_scan.py
6 aged pages 5.1 MB 2.1 MB
10 book pages 6.5 MB 4.7 MB

Our scans were color JPEG. It writes gray JPEG pages at quality 75. With --color, the 6 pages came to 2.3 MB.

Then turn it into text

Our Apify Actor turns scanned PDFs into Markdown and text. Its code is in the readers table above.

The free plan takes 20 pages a run, 50 a month. An OCR page costs $0.006.

Try the Actor

How I tested it
  • 6 made-up pages (a letter, a memo, an invoice, two columns, 8 pt small print, a form), each in 8 aged kinds as simulated scans: 48 pictures.
  • 10 real pages of 2 public domain books, 5 on tan paper.
  • 24 new page scans in 4 new kinds (blue, pink, darker paper, a deeper shadow), made after the script was frozen.
  • Tesseract 5.5.4, Apple Vision on macOS 26.6, OCRmyPDF 17.13.0, ImageMagick 7.1.2, unpaper 7.0.0. Our Actor's code at commit 528fe416 (build 0.1.102). No Apify run.
What I did not test

ScanTailor, Acrobat's Enhance Scans, online tools, phone scanner apps, color documents with stamps, handwriting, 1-bit scans, and languages other than English.

Questions people ask

How do I enhance a scanned PDF for free?

Run clean_scan.py on it. It turns yellow, gray or shadowed paper white and makes the text darker. Then run OCRmyPDF if you want search. Both are free.

How do I remove the yellow background from a scan?

Divide the page by a blurred copy of itself, then stretch the levels. clean_scan.py does that. A plain levels change only partly fixes a shadow, because it uses one setting for the whole page.

Does cleaning a scan improve OCR?

On bad scans, yes: Tesseract found 943 of 966 words on our fully aged pages, up from 721. On 10 real book pages it barely changed the words.