OCRmyPDF
Install OCRmyPDF and Tesseract to create searchable PDFs from scanned documents.
ansible-playbook -i inventory -K playbooks/lab-stack.yml --tags ocr🔧 Manual setup and configuration
- Log out and log back in after running the role so Nautilus/Nemo reload user actions.
- In Nautilus, right-click a PDF and use OCR PDF (ocrmypdf).
- The action runs
~/.local/bin/ocrmypdf-wrapperand writes*_ocr.pdfnext to the original file. - The wrapper defaults to German + English OCR (
-l deu+eng) and skips pages that already contain text. - Review
~/.cache/ocrmypdf-wrapper.logif conversion fails.
✅ Check
ocrmypdf --version
tesseract --versionExpected: both commands print a version.
echo "test" > /tmp/ocr-test.txt
enscript /tmp/ocr-test.txt -o - | ps2pdf - /tmp/ocr-test.pdf
ocrmypdf -l eng /tmp/ocr-test.pdf /tmp/ocr-test_ocr.pdf
pdfinfo /tmp/ocr-test_ocr.pdf | sed -n '1,5p'Expected: /tmp/ocr-test_ocr.pdf is created successfully.
ls -l ~/.local/share/file-manager/actions/ocrmypdf.desktop
ls -l ~/.local/share/nemo/actions/ocrmypdf.nemo_actionExpected: at least one action file exists (depending on your file manager).
Nautilus right-click action behavior
- Menu entry:
OCR PDF (ocrmypdf) - File type: appears for PDF files (
application/pdf) - Execution: calls
~/.local/bin/ocrmypdf-wrapper "%f" - Output naming: input
paper.pdfbecomespaper_ocr.pdf - Batch behavior: the wrapper accepts multiple files and processes each one in sequence
- Troubleshooting: if the menu entry does not appear, restart Nautilus (
nautilus -q) or relogin
Folder-based batch processing
Use this standalone script to process all PDFs stored directly in pdfs/ in one run. Folder-based batch processing is its purpose; Docker is simply the runtime used by this script. The file-manager action described above runs the locally installed OCRmyPDF and does not require Docker.
Standalone script
The script uses the jbarlow83/ocrmypdf Docker image and English + German language data (eng+deu). Docker must be installed and running; see Docker setup. It writes the processed files to ocr_output/, does not recurse into subfolders, and leaves the originals unchanged. Save it as ocr-pdf-folder.sh in the directory containing pdfs/:
#!/usr/bin/env bash
set -euo pipefail
shopt -s nullglob
pdf_dir="pdfs"
output_dir="ocr_output"
pdf_files=("$pdf_dir"/*.pdf)
if ((${#pdf_files[@]} == 0)); then
printf 'No PDF files found in %s\n' "$pdf_dir" >&2
exit 1
fi
mkdir -p "$output_dir"
for pdf_file in "${pdf_files[@]}"; do
base_name="${pdf_file##*/}"
output_file="$output_dir/${base_name%.pdf}_ocr.pdf"
docker run --rm --user "$(id -u):$(id -g)" \
--volume "$PWD:/mnt" \
jbarlow83/ocrmypdf \
--language eng+deu \
"/mnt/$pdf_file" "/mnt/$output_file"
doneRun the script from its directory after placing the input files in pdfs/:
chmod +x ocr-pdf-folder.sh
./ocr-pdf-folder.shThe script uses English + German (eng+deu). Change the language code to match your documents; for example, use --language eng for English-only documents. This container workflow is separate from the installed wrapper, which defaults to German + English (deu+eng).
Why this software?
OCRmyPDF is preferred for the workstation setup because it runs locally, adds a searchable text layer while preserving the original PDF, and provides a mature command-line workflow for rotation, deskewing, optimization, and PDF/A output. It also works without an account, API key, document upload, or separate model service and integrates directly with the automated file-manager action above.
Consider an alternative when the task is broader than making scanned PDFs searchable:
- Mistral OCR can extract document structure and content for downstream AI workflows. It is a hosted API, so review costs, credentials, and data-handling requirements before uploading research or institutional documents.
- PaddleOCR provides trainable, deep-learning OCR and document-layout models for many languages and complex extraction pipelines. It requires more model/runtime setup, and producing a searchable archival PDF needs additional pipeline work.
- Baidu Unlimited OCR is a managed OCR option for high-volume or application-integrated extraction. It requires a Baidu cloud account and sending documents to an external service; confirm current service limits, pricing, supported regions, and privacy terms before use.