Linux PDF OCR: OCRmyPDF and Tesseract command-line guide
Table of contents
Nutrient Document Engine runs in your infrastructure, and Docker gets you up in minutes.
To OCR a scanned PDF on Linux, install OCRmyPDF(opens in a new tab) and run ocrmypdf input.pdf output.pdf. It adds a searchable text layer using optical character recognition (OCR). Use Tesseract(opens in a new tab) directly for image input, or Nutrient Document Engine when you need an HTTP API in your document-processing infrastructure.
This guide covers installation on Ubuntu, Debian, and Fedora; language packs; scan cleanup; and batch processing. It also explains the difference between downloading an OCR result and storing a document in Document Engine.
Skip the install: One API call
If this OCR needs to run inside an application rather than on your own machine, you don’t have to maintain Tesseract and OCRmyPDF on a server. Nutrient’s PDF OCR API does the same job as one HTTPS request, with a free tier and no credit card. The Document Engine section later in this guide shows the self-hosted route.
OCR a scanned PDF from the terminal with Nutrient CLI
If you want the text out of a scan rather than a searchable PDF, the Nutrient PDF-to-Markdown CLI runs OCR from the command line on Linux, macOS, and Windows. Install it from npm and convert with --vision, which handles scans, handwriting, and complex layouts:
npm install -g @pspdfkit/pdf-to-markdownpdf-to-markdown --vision scan.pdf scan.mdStandard conversion of born-digital PDFs needs no account. Vision mode needs a Nutrient API key, which you create in the PDF-to-Markdown dashboard(opens in a new tab) and set as NUTRIENT_API_KEY for scripts and CI. The CLI reference lists every command and option. The output is Markdown or text, not a PDF; for a searchable PDF, use OCRmyPDF below or the API above.
OCR a PDF from the Linux command line with OCRmyPDF
This next section walks through installing OCRmyPDF on Linux and running OCR on a PDF from the terminal.
Why not use Tesseract directly?

Tesseract recognizes text in images and can produce searchable PDFs, but it doesn’t accept PDF input directly. OCRmyPDF handles the PDF workflow around OCR: rasterizing pages when needed, applying optional image cleanup, and adding a text layer.
For a JPG or PNG, Tesseract may be enough. For an existing scanned PDF, OCRmyPDF handles the extra PDF processing. Inspect the output from either tool; OCR doesn’t guarantee error-free text.
Installing OCRmyPDF
Install OCRmyPDF using the following command on Ubuntu- or Debian-based systems:
sudo apt-get install ocrmypdfFor Fedora, you can use the following command:
sudo dnf install ocrmypdf tesseract-osdDistribution packages may lag behind the latest OCRmyPDF release. The installation guide(opens in a new tab) recommends installing system dependencies first and then using uv(opens in a new tab) for a newer Python package when needed:
uv tool install ocrmypdfocrmypdf --versionInstall uv first if it isn’t available. Confirm that the ocrmypdf command resolves to the intended installation. Python packaging tools don’t install every external dependency: Tesseract and the selected PDF rasterizer must also be available.
For optional cleanup with --clean, install unpaper(opens in a new tab). On Fedora, include tesseract-osd for page-orientation detection. Refer to the installation guide for version-specific dependencies and language packages.
Basic usage
To use OCRmyPDF, run the following command. Replace input.pdf with the path to your PDF, and output.pdf with the path where you want to save the OCR’d result:
ocrmypdf input.pdf output.pdfOpen output.pdf and check that you can select and search for text. The default output mode and PDF/A conversion depend on your OCRmyPDF version and installed dependencies. If archival conformance is required, request --output-type pdfa explicitly and validate the result. To request an ordinary PDF, use:
ocrmypdf --output-type pdf input.pdf output.pdfTo run OCR on selected pages:
ocrmypdf --pages 2,3,13-17 input.pdf output.pdfOCR in a language other than English
By default, OCRmyPDF assumes a document is in English. For other languages, specify the language to improve recognition:
ocrmypdf -l rus russian_doc.pdf russian_doc_ocr.pdfIf the document is multilingual, you can pass in multiple languages:
ocrmypdf -l rus+eng russian_doc.pdf russian_doc_ocr.pdfCheck the Tesseract documentation(opens in a new tab) for supported languages.
Install any required language packs using these instructions(opens in a new tab).
Image processing
OCRmyPDF offers optional preprocessing. Start with the smallest set of options needed for your scans:
- Page rotation —
--rotate-pagesdetects orientation. - Deskewing —
--deskewstraightens a tilted scan. - OCR cleanup —
--cleanuses unpaper on the image supplied to OCR. - Output cleanup —
--clean-finalalso puts the cleaned image in the final PDF.
The image-processing documentation(opens in a new tab) explains the order of these operations and their limits. Review the resulting pages: Cleanup and rasterization can alter visible content.
File optimization
Image optimization and Fast Web View linearization are separate settings. Use --optimize 0 to disable image optimization. The default level, --optimize 1, applies lossless optimizations; levels 2 and 3 permit lossy changes.
Linearization depends on the --fast-web-view size threshold. Don’t assume that disabling image optimization also disables linearization. Check the optimization documentation(opens in a new tab) and your installed version’s ocrmypdf --help output.
Batch processing PDF files
Use --jobs to limit how much parallel work OCRmyPDF performs:
ocrmypdf --jobs 4 input.pdf output.pdfFor a folder of PDFs, write the results to a separate output directory so a later run won’t treat them as new inputs:
mkdir -p ocr-outputfor file in ./*.pdf; do [ -f "$file" ] || continue ocrmypdf --jobs 4 "$file" "ocr-output/${file##*/}" || breakdoneThe loop stops at the first failed conversion. Inspect that file and the error before continuing. Files that already contain text may need --skip-text; use it only if you want to keep their existing text layers.
Troubleshooting Linux OCR
- The command isn’t found — Check the installation and
PATH. Then runocrmypdf --version. - A language is unavailable — Install its Tesseract language pack and check
tesseract --list-langs. - The PDF already contains text — Decide whether to preserve that text or replace an old OCR layer. Don’t force OCR without understanding that it can rasterize page content.
- Recognition is poor — Check the language, resolution, page orientation, and scan quality. Compare important values with the original.
- You only need text output — The
--sidecar output.txtoption writes recognized text separately. It doesn’t include existing text from pages that weren’t OCR’d.
How to OCR a PDF on Linux using Nutrient Document Engine
Nutrient Document Engine runs document operations through an HTTP API. You can deploy it in your infrastructure or use a hosted option. Its OCR action adds searchable text; extracting named fields or table data is a separate operation.
OCR capabilities and deployment requirements
Document Engine supports OCR in multiple languages and can combine OCR with other document operations. From version 1.16.0, GdPicture OCR is the recommended engine when available; Core OCR is deprecated. Consult the OCR guide for licensing and configuration.
For a deployment that stores documents, plan for PostgreSQL and file storage as well as the Document Engine container. The requirements guide recommends starting with 2–4 CPU cores and 4–8 GB of memory. Size these resources for your workload. Both x86_64 and ARM64 processors are supported.
Setting up Docker
Document Engine is provided as a Docker container. To deploy it, install Docker for your operating system:
- macOS — Install and start Docker Desktop for Mac. Refer to the Docker website(opens in a new tab) for instructions.
- Windows — Install and start Docker Desktop for Windows. Refer to the Docker website(opens in a new tab) for instructions.
- Linux — Install Docker Engine. Refer to the Docker website(opens in a new tab) for instructions.
Launching Document Engine
Once Docker is installed, follow the steps outlined below to start Document Engine.
- Open your terminal:
- macOS — You can use a terminal integrated within your integrated development environment (IDE) or standalone applications like
Terminal.apporiTerm2. - Windows/Linux — Use any terminal emulator or the one provided in your IDE.
- macOS — You can use a terminal integrated within your integrated development environment (IDE) or standalone applications like
- Enter the following command to start the service:
docker run --rm -t -p 127.0.0.1:5000:5000 -e API_AUTH_TOKEN=secret pspdfkit/document-engine:1.16.0This is a local quickstart pinned to Document Engine 1.16.0, using a sample token. Follow the deployment quickstart for a current deployment and persistent storage. Don’t reuse the sample token in production.
Wait until the container reports that it has started. Its log includes the version, for example:
[info] 2026-05-29 18:56:45.286 Running Document Engine version 1.16.0Installing curl
Document Engine exposes an HTTP API, so you interact with it by sending commands and documents in HTTP requests. Make sure curl is installed:
- macOS —
curlis preinstalled, so no additional steps are required. - Windows — Download and install
curlfrom the official site(opens in a new tab). - Linux — Use your package manager (e.g.
sudo apt-get install curlfor Debian/Ubuntu).
Performing OCR with Nutrient Document Engine
Once Document Engine is running, you can perform OCR on your PDFs by sending requests to its API. The first two examples require persistent storage configured through the deployment quickstart. For the standalone container above, use the third example, /api/build.
Running OCR on document upload
To perform OCR when uploading a new document, use the
ocraction within theinstructionsparameter in your API request:Terminal window curl --fail-with-body -X POST http://localhost:5000/api/documents \-H "Authorization: Token token=secret" \-F instructions='{"parts": [{"file": "document"}],"actions": [{"type": "ocr","language": "english"}]}' \-F document=@/path/to/ExampleDocument.pdf \-o upload.jsonPOST /api/documents HTTP/1.1Content-Type: multipart/form-data; boundary=customboundaryAuthorization: Token token=secret--customboundaryContent-Disposition: form-data; name="instructions"Content-Type: application/json{"parts": [{"file": "document"}],"actions": [{"type": "ocr","language": "english"}]}--customboundaryContent-Disposition: form-data; name="document"; filename="Example Document.pdf"Content-Type: application/pdf<PDF data>--customboundary--This request stores the processed document and saves the API’s JSON response to
upload.json. It doesn’t download the PDF. For a PDF response, use the/api/buildexample below.Applying OCR to existing documents
If you have a document already uploaded to Document Engine, you can apply OCR using the
apply_instructionsendpoint:Terminal window curl --fail-with-body -X POST http://localhost:5000/api/documents/:document_id/apply_instructions \-H 'Authorization: Token token=secret' \-H "Content-Type: application/json" \-d '{"parts": [{"document": {"id": "#self"}}],"actions": [{"type": "ocr","language": "english"}]}' \-o update.jsonPOST /api/documents/:document_id/apply_instructions HTTP/1.1Content-Type: application/jsonAuthorization: Token token=secret{"parts": [{"document": {"id": "#self"}}],"actions": [{"type": "ocr","language": "english"}]}Replace
:document_idwith your document’s ID. The#selfanchor refers to the current document. This operation updates the stored document;update.jsonis the API response, not an exported PDF.Running OCR and retrieving the result without storing
To upload a PDF and download the OCR result without persisting a document in Document Engine, use /api/build. The upload field and parts[].file must both be named document:
curl --fail-with-body -X POST http://localhost:5000/api/build \ -H "Authorization: Token token=secret" \ -F instructions='{ "parts": [ { "file": "document" } ], "actions": [ { "type": "ocr", "language": "english" } ] }' \ -F document=@/path/to/ExampleDocument.pdf \ -o result.pdfPOST /api/build HTTP/1.1Content-Type: multipart/form-data; boundary=customboundaryAuthorization: Token token=secret
--customboundaryContent-Disposition: form-data; name="instructions"Content-Type: application/json
{ "parts": [ { "file": "document" } ], "actions": [ { "type": "ocr", "language": "english" } ]}--customboundaryContent-Disposition: form-data; name="document"; filename="Example Document.pdf"Content-Type: application/pdf
<PDF data>--customboundary--Performance considerations
OCR consumes CPU resources. Benchmark representative documents with your selected OCR engine, language, and concurrency limits. Size workers and memory from those measurements; timings from another engine or development machine aren’t a service guarantee.
OCRmyPDF vs. Tesseract vs. Nutrient Document Engine
Choose based on input format and deployment requirements:
| Criteria | OCRmyPDF | Tesseract directly | Nutrient Document Engine |
|---|---|---|---|
| Input | Existing PDFs; some image input | Images; no direct PDF input | PDF and supported image input |
| Output | Searchable PDF/PDF/A; optional text sidecar | Text, hOCR, TSV, or searchable PDF | Searchable PDF; separate extraction options |
| Preprocessing | Optional PDF and image processing | Configure or prepare images yourself | Depends on the OCR operation and engine |
| Integration | CLI and Python workflows | CLI or library integration | HTTP API |
| Deployment | Local installation or container | Local installation | Self-hosted or hosted |
| Best fit | OCR of existing PDFs from the terminal | Image OCR with low-level control | Document operations in a server workflow |
Conclusion
Use OCRmyPDF for adding searchable text to scanned PDFs from a Linux terminal. Use Tesseract directly when your inputs are images. For an HTTP API integrated with other document operations, evaluate Nutrient Document Engine.
Start with the Document Engine quickstart or contact Sales to discuss deployment and licensing.
Related reading
- Tesseract OCR in Python — The Python path to the same engine, with configuration and tuning
- OCR a PDF with the Nutrient OCR API — A hosted REST alternative to running OCR locally
- Document AI vs. OCR — How OCR relates to broader document understanding
- PDF data extraction developer guide — Approaches for extracting text and structured data from PDFs
- Barcode and OCR extraction — Reading barcodes alongside text during OCR
FAQ
OCRmyPDF adds a searchable text layer to scanned PDFs. It uses an OCR engine such as Tesseract and offers optional preprocessing. A searchable text layer doesn’t turn a scan into a fully editable source document.
Use sudo apt-get install ocrmypdf on Ubuntu/Debian, or sudo dnf install ocrmypdf tesseract-osd on Fedora. For a newer version, follow the upstream instructions for installing system dependencies and the Python package with uv.
You can specify the language using the -l flag. For example, to OCR in Russian:
ocrmypdf -l rus input.pdf output.pdf
Run ocrmypdf input.pdf output.pdf after installation. Verify search, text selection, and the visual result. Optional preprocessing can help poor scans, but some settings alter the page image.
Use a shell loop with a separate output directory, as shown above. The --jobs option limits parallel work within each conversion. Check failed files before continuing the batch.
Document Engine exposes OCR and other document operations through an HTTP API. It supports self-hosted and hosted deployments and can work with Nutrient client SDKs. Choose it when you need those integration and deployment options.
Deploy Document Engine, configure its API token, and send a multipart request with an OCR action. Use /api/build to download a PDF result, or /api/documents to store a document. The complete examples above show the different response handling.