Introduction
OCRmyPDF takes a scanned PDF (image-only) and produces a PDF/A output that contains a hidden text layer under each page image. The text layer is generated by Tesseract OCR and positioned to match the visual layout, making the file fully searchable while keeping the original scan intact.
What OCRmyPDF Does
- Adds an invisible OCR text layer to scanned PDFs without degrading image quality
- Produces PDF/A-compliant archival output by default
- Skips pages that already contain text to avoid double-processing
- Automatically deskews, cleans, and rotates pages before OCR
- Supports batch processing of entire directories
Architecture Overview
OCRmyPDF orchestrates a pipeline of external tools: Ghostscript for PDF rendering, unpaper for image cleaning, Tesseract for OCR, and pikepdf for reassembling the final PDF. Each page is processed in parallel. The text layer is positioned using hOCR coordinate data so that selecting text in a viewer highlights the correct region.
Self-Hosting & Configuration
- Install via pip, conda, or your distro's package manager (apt, brew, etc.)
- Tesseract and Ghostscript must be available on the system PATH
- Install extra Tesseract language packs for non-English documents
- Use
--output-type pdfa(default) for archival;--output-type pdfto skip PDF/A conversion - Run inside Docker with
jbarlow83/ocrmypdffor an isolated environment
Key Features
- Lossless by default: the original scanned images are not re-encoded
- Produces PDF/A for long-term archival compliance
- Multithreaded page processing for fast throughput on multi-core machines
- Plugin system for custom pre-processing or alternative OCR engines
- Handles mixed documents (pages with and without existing text)
Comparison with Similar Tools
- Tesseract CLI — raw OCR to plain text; OCRmyPDF wraps it into a full PDF pipeline
- Adobe Acrobat — commercial; OCRmyPDF is free and scriptable
- pdfsandwich — similar concept but fewer configuration options and slower development
- Paperless-ngx — document management system that uses OCRmyPDF internally
FAQ
Q: Does it reduce scan quality? A: No. By default OCRmyPDF copies the original images without re-encoding.
Q: Which languages are supported? A: Any language Tesseract supports, currently over 100.
Q: Can it process thousands of files? A: Yes. Use a shell loop or GNU parallel; each invocation is self-contained.
Q: Does it work on born-digital PDFs? A: It detects existing text layers and skips those pages unless forced.