A scanned PDF looks like a normal document, but it behaves like a stack of photographs. You can't search it, you can't copy a paragraph, and a lot of scripts that "extract text" come back empty. I run into this constantly while building file tools: someone emails a "PDF" that is really a photograph of a page. Here's how I tell the difference, and how I add a real text layer with OCRmyPDF and Tesseract.
Is it actually a scan?
The quickest check is still pdftotext, from poppler-utils:
pdftotext input.pdf - The trailing - prints to the terminal. If you only get a blank line, or a form-feed character and nothing else, there is no text layer to read. If you can already highlight and copy sentences in a viewer, you don't need OCR at all.
A file can also be mixed: a report exported from Word, with a couple of scanned signature pages at the end. That's worth remembering when you choose flags later.
OCRmyPDF, not Tesseract alone
Tesseract is the engine that looks at an image and guesses the characters. It's excellent, and you can run it directly on a PNG:
tesseract page.png stdout A PDF is a more awkward input. You'd have to render each page to an image, OCR it, and then stitch a hidden text layer back onto the original page so the file still looks the same. OCRmyPDF is the tool that does that pipeline well. It uses Tesseract (and a few PDF libraries) and writes a searchable PDF.
Install it, plus Tesseract and a language pack:
# Debian/Ubuntu sudo apt install ocrmypdf tesseract-ocr tesseract-ocr-eng # macOS brew install ocrmypdf # or: pip install ocrmypdf # and install Tesseract and Ghostscript yourself tesseract --list-langs shows what's installed. English is eng. Add more packs (for example tesseract-ocr-fra or tesseract-ocr-deu) if the document isn't in English.
The basic command
ocrmypdf -l eng --output-type pdf input.pdf searchable.pdf -l eng tells Tesseract which language to expect. --output-type pdf asks for a regular PDF. I set that on purpose: OCRmyPDF's default is to write PDF/A-2b, which is a strict archival flavour of PDF. That's useful when you want an archive copy, but it's a surprising side effect if you only wanted to search the file, and the conversion can fail on unusual inputs. For "make this searchable and leave me alone", --output-type pdf is the safer default.
After it finishes, run pdftotext again. You should see the words. In a PDF viewer you can also select them, even though the page still looks like the original scan. What OCRmyPDF added is an invisible text layer sitting on top of (or rather, behind) the page image.
If you also want a plain text file, add a sidecar:
ocrmypdf -l eng --output-type pdf --sidecar output.txt input.pdf searchable.pdf That writes output.txt as well as the PDF. Handy when you're feeding the text into something else and don't want to parse the PDF a second time.
Images, languages and mixed files
OCRmyPDF will also take an image, not only a PDF:
ocrmypdf -l eng --image-dpi 150 --output-type pdf scan.png searchable.pdf --image-dpi matters when the file has no DPI of its own. A photo from a phone often doesn't. If you get a page that's huge or tiny, this is the first flag to check.
For more than one language on the same page, join the codes with +:
ocrmypdf -l eng+fra --output-type pdf input.pdf searchable.pdf On mixed documents, I usually start with --skip-text, which leaves pages that already have a text layer alone and only OCRs the others:
ocrmypdf -l eng --output-type pdf --skip-text mixed.pdf searchable.pdf --force-ocr is the opposite: it OCRs every page, even ones that already have text. That's useful when the existing text is garbled (a bad export, a messy Unicode map). The risk is that you can end up with two text layers on a good page, so I don't use it as the default.
A few other flags I actually use:
-
--pages 3-5to try the process on a few pages before committing a 400-page scan. -
--rotate-pagesif some pages were scanned upside down or on their side. OCRmyPDF can detect that and correct it. -
-j 4to run a few pages in parallel.
Accuracy still depends on the scan. Skewed phone photos, tiny type, stamps over words and heavy compression are the usual causes of errors. Proof-read names, amounts and dates. OCR is practical, not perfect.
When I don't bother with the terminal
For a pipeline or a folder of archives, I always use OCRmyPDF. When a colleague just needs one contract made searchable, installing Tesseract on their laptop is a lot to ask. I built a free PDF OCR tool on OneFileKit, with no sign-up. You upload the PDF, pick a language and an output format (plain text, Word, or a searchable PDF), and download the result. Uploaded files are deleted after 60 minutes.
If the PDF already has selectable text and you only want that text out of it, a PDF to text extract is the shorter path. Use OCR when copying from the file gives you nothing.
Wrapping up
- Empty
pdftotextoutput is the simplest sign that a PDF is only a scan. - OCRmyPDF wraps Tesseract and writes a hidden text layer; the page still looks the same.
- Prefer
--output-type pdfunless you specifically want PDF/A. - Use
--skip-texton mixed files, and--sidecarif you also want a.txt. - Always read the result. Bad scans produce confident-looking mistakes.
What's the largest scanned batch you've had to make searchable? I'd like to know which flags ended up mattering.


