OCRmyPDF has a built-in optimizer that shrinks the JPEG content of the output, with –optimize levels 0 to 3 and –jpeg-quality to set the quality. The optimizer works on both plain PDFs and PDF/A output. This guide runs it on one scanned PDF.
Prerequisites
OCRmyPDF installed with Tesseract, and a scanned PDF. Work on a copy of the file.
Steps
1. Check the OCRmyPDF version
Run ocrmypdf –version in a terminal. Expected result: a version number prints.
2. Run OCRmyPDF with the optimizer
Run ocrmypdf –optimize 2 –jpeg-quality 60 input.pdf output.pdf. Expected result: output.pdf is created.
3. Compare the file sizes
Compare the sizes of input.pdf and output.pdf. Expected result: the output file is smaller than the input.
4. Check the text still searches
Search output.pdf for a word from the page. Expected result: the search returns a hit, proving the OCR layer is present.
Practice check: fictional 8-page scanned report, optimizer level 2
The table below is fictional practice material. It lists the four checks for the optimized file.
| Check | Expected result |
|---|---|
| Version printed | A version number prints |
| Output created | output.pdf exists |
| Size reduced | Smaller than the input |
| Text searchable | harvest returns a hit |
Expected result. the optimized file is created, it is smaller than the input, and the word harvest is still searchable in it.
Limits
- The optimizer shrinks images, not text; a file that is large because of embedded fonts or vector art will not shrink much, so check what makes the file big first.
- UNTESTED – no OCR tool or AI tool was run; all results above are expected results. The practice file is fictional.
Sources
- OCRmyPDF Cookbook – –sidecar writes OCR text to a companion file; –output-type pdfa/pdf picks the output; –optimize shrinks the file; –mode strip removes the text layer. Checked 2026-11-29.
- How to Compress a PDF on Linux (Ghostscript, qpdf, GUI) – Ghostscript -dPDFSETTINGS presets are /screen, /ebook, /printer and /prepress; qpdf –linearize gives lossless cleanup. Checked 2026-11-29.
