Most "search inside PDFs" advice assumes every PDF has a text layer. In practice, a folder of contracts or scanned invoices is a mix: some files are exported from Word, some are photos of paper, some are 300-page scans where only page 4 matters.
This post is about the second group. Specifically: what you get for free from the OCR engine that ships with Windows, how to call it from Python, and where it quietly produces garbage.
The engine
Windows 10/11 ships an OCR API in the Windows.Media.Ocr namespace. It runs locally, needs no API key, and supports whatever language packs are installed in Settings β Language.
From Python, the usual route is the winrt projection:
from winrt.windows.media.ocr import OcrEngine from winrt.windows.graphics.imaging import BitmapDecoder, SoftwareBitmap from winrt.windows.storage import StorageFile, FileAccessMode
Enter fullscreen mode
Exit fullscreen mode
You hand it a SoftwareBitmap and get back lines of text with bounding boxes.β¦