ConfigsJul 13, 2026·2 min read

OCRmyPDF — Add Searchable Text Layers to Scanned PDFs

Adds an accurate OCR text layer to scanned PDF files so they become searchable, copy-pasteable, and accessible, while preserving the original scan quality.

Agent ready

Ready-to-run agent install

This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
OCRmyPDF Overview
Direct install command
npx -y tokrepo@latest install 4d40ca36-7eb7-11f1-9bc6-00163e2b0d79 --target codex

Run after dry-run confirms the install plan.

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 pdf to skip PDF/A conversion
  • Run inside Docker with jbarlow83/ocrmypdf for 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.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets