Run OCRmyPDF Inside Docker Container on Linux

Run OCRmyPDF Inside Docker Container on Linux

OCRmyPDF is a command-line tool that adds an OCR text layer to scanned PDF documents, making their contents searchable and easier to process. Running OCRmyPDF from a Docker container avoids installing its dependencies directly on Linux and provides a consistent environment for PDF processing.

First, download a sample PDF for testing:

curl -sSo test.pdf https://raw.githubusercontent.com/ocrmypdf/OCRmyPDF/main/tests/resources/multipage.pdf

OCR processing can then be performed inside a Docker container, with OCRmyPDF arguments passed as usual:

docker run -it --rm -v ./:/data jbarlow83/ocrmypdf --skip-text test.pdf result.pdf

The command consists of several parts:

  • docker run - starts a new container.
  • -it - allows interaction with the container through the terminal.
  • --rm - removes the container once the command finishes.
  • -v ./:/data - makes the current directory available inside the container at /data.
  • jbarlow83/ocrmypdf - specifies the Docker image containing OCRmyPDF.
  • --skip-text - leaves pages that already contain a text layer unchanged.
  • test.pdf - identifies the source PDF that will be processed.
  • result.pdf - defines the name of the generated PDF.

Once the container completes the operation, the OCR-enabled document is available as result.pdf in the current directory. This approach keeps OCRmyPDF isolated from the host system while allowing PDF files to be processed directly from the command line.

Leave a Comment

Cancel reply

Your email address will not be published.