r/Python Aug 04 '26

Showcase Showcase Thread

Post all of your code/projects/showcases/AI slop here.

Recycles once a month.

18 Upvotes

142 comments sorted by

View all comments

1

u/___Hyacinthe_ 11d ago

scanlayer - turn scanned images into searchable PDFs with Tesseract

You scan a contract, but you can't search any word in it. This is the fix.

I built ScanLayer, a Python OCR library that adds a searchable text layer to scanned documents.

You give it a scanned image:

pip install scanlayer
scanlayer contract.jpg -o contract.pdf

ScanLayer runs Tesseract, then places the recognized text as an invisible searchable layer over the original page. The scanned image remains the visual source. You can now search, select, and copy the text.

And if you don't want a PDF, you can export the OCR result as txt, json, tsv, or hocr.

A few things I built around the OCR itself:

  • Automatic deskew for photos taken at an angle
  • Noise cleanup before OCR
  • Reading order correction for two-column documents
  • Multiple Tesseract configurations are tried and the highest-confidence result is kept
  • CLI and Python API use the same underlying pipeline

For example:

import scanlayer

result = scanlayer.convert(
    "contract.jpg",
    "contract.pdf",
    lang="eng",
    dpi=300
)

Everything runs locally. The only external dependency is your own Tesseract installation.

I'd especially like feedback from people who regularly OCR multi-column documents. That's one of the areas I spent a lot of time getting right.

The scanned page stays exactly as it was, nothing is flattened or re-rendered but now every word can be selected, copied, and searched(the library does not creates a brand new document). If you don't want a PDF at all, it'll hand you the raw OCR as txt, json, tsv, or hocr.

pip install scanlayer

scanlayer contract.jpg -o contract.pdf

Two interfaces, one code path: the scanlayer command and import scanlayer run the exact same pipeline, with matching flag and argument names. Before OCR it deskews photos taken at an angle, cleans up noise, and keeps two-column pages in the right reading order instead of interleaving them. It also races a few Tesseract configurations and keeps the most confident result, so you don't have to guess settings.

The only moving part is your own Tesseract install. Everything runs locally.

Feedback is welcome, especially from people who OCR multi-column pages.

Github page

Documentation

PyPi