Tools,

OCRmyPDF on an encrypted PDF: exit 8, fixed

qpdf --decrypt \
  --password=open-pass \
  locked.pdf - \
  | ocrmypdf - searchable.pdf

An open password stops OCRmyPDF. Remove it with your password, then run OCR.

Fix exit 8

Open passwords and signatures stopped it

OCRmyPDF 17.13.0 on 8 copies of one scan
The PDF OCRmyPDF
No lock (the control) OCR done
Open password, 256-bit AES Exit 8
Open password, 128-bit AES Exit 8
Open password, 128-bit RC4 Exit 8
Owner password only, 256-bit AES OCR done, lock gone
Owner password only, 128-bit RC4 OCR done, lock gone
Signed Exit 2
Empty signature box Exit 2

Exit 8 is "Input PDF is encrypted". Exit 2 is OCRmyPDF's code for any input problem. Here it said "Input PDF has a digital signature".

Every 10-page OCRmyPDF run that finished, before or after a fix, found the same 1,876 of 1,955 words as the control.

You know the password: qpdf --decrypt

qpdf --decrypt --password=open-pass locked.pdf unlocked.pdf
ocrmypdf unlocked.pdf searchable.pdf

Put your own password after --password=. The top line skips the unlocked.pdf file. The output has no password: lock it again if you need one.

Unlock only files that you own or have the right to change.

The same fix in Python

import ocrmypdf
import pikepdf

with pikepdf.open("locked.pdf", password="open-pass") as pdf:
    pdf.save("unlocked.pdf")
ocrmypdf.ocr("unlocked.pdf", "searchable.pdf")

pikepdf comes with OCRmyPDF, so there is nothing new to install. Its save() drops the encryption unless you pass encryption=.

I ran it as printed on 2 pages of our scan. It found the same 353 of 381 words as the qpdf way.

An owner password alone does not stop it

To keep the limits, lock the output again (next section).

Signed PDFs: one flag, one broken signature

A signature covers the file's bytes, and OCR changes them. This flag lets OCRmyPDF run:

ocrmypdf --invalidate-digital-signatures signed.pdf searchable.pdf

Put the password back after OCR

qpdf --encrypt open-pass owner-pass 256 -- searchable.pdf searchable-locked.pdf

pdftotext -upw open-pass read the same words from the locked copy. With no password, pdftotext and OCRmyPDF both stopped.

For an owner-only lock, write "" for the open password. Add --print=none --extract=n --modify=none before the --.

Our Actor reads owner-locked and signed PDFs

PDF OCR to Markdown, our Apify Actor, read the owner-only, signed and empty-box copies as they were. Each gave the same text as the plain scan.

It has no password field. A file with an open password fails with "The PDF is password-protected." and gets no page charge.

What I did not test

How I tested it
  • The scan of count words in a PDF: 10 proofread book pages from Wikisource, a 300 ppi image-only PDF. 1,955 words.
  • Locks: qpdf --encrypt, with the passwords open-pass and owner-pass. The owner-only copies block print, copy and changes.
  • Signature: pyHanko sign addsig with a self-signed test certificate. Empty box: pyHanko sign addfields, which sets the form flag on its own.
  • Each 10-page run: ocrmypdf -l eng --jobs 2 --sidecar, at nice 19 and background priority, one run at a time.
  • Words found: sidecar words that are right and in the right order. pdftotext on the same PDFs finds 1,853, as in our word count test.
  • Each ocrmypdf, qpdf, pdftotext and Python command on this page ran as printed on a 2-page copy of the scan.
  • No speed ranking: other jobs kept the Mac busy.
  • OCRmyPDF 17.13.0, pikepdf 10.17.0, qpdf 12.4.2, Tesseract 5.5.4, pyHanko 0.38.2, Poppler 26.03.0 (pdfsig, pdftotext), Python 3.13.11, macOS 26.6 (arm64).
  • Scripts and results stay in our private repo, in research/bench/ocrmypdf-encrypted-pdf-2026-11-23/.
Sources

Questions people ask

How do I OCR a password-protected PDF with OCRmyPDF?

OCRmyPDF has no password option. Remove the open password first, with the password you have: qpdf --decrypt --password=YOUR-PASSWORD locked.pdf unlocked.pdf. Then run ocrmypdf unlocked.pdf searchable.pdf.

Why does OCRmyPDF say "Input PDF is encrypted"?

The PDF needs a password to open. OCRmyPDF stops with exit code 8 and does not ask for one. In our test, a PDF with only an owner password did not cause this error.

Does OCRmyPDF keep a PDF's password and limits?

No. Our owner-only PDFs came out with no encryption, so their print and copy limits were gone, and OCRmyPDF gave no warning. Lock the output again with qpdf --encrypt if you need them.

What does --invalidate-digital-signatures do?

It lets OCRmyPDF run on a signed PDF. The signature stays in the output, but pdfsig and pyHanko no longer call it valid. If you sign the PDF yourself, run OCR first and sign after.

Two ways to skip the work

Run it yourself. Our Apify Actor turns scanned PDFs into Markdown, tables included.

Try the Actor

Or send us the scan. Tack, our AI, does the job for $29, up to 50 pages. First page free.

Get one page free