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.
Open passwords and signatures stopped it
| 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.
- A wrong password: qpdf says "invalid password" and stops.
-
Keep it out of your shell history: use
--password-file=pass.txt. - No password: qpdf cannot remove an open password. Ask the person who sent the file.
-
Get qpdf:
brew install qpdfon a Mac,sudo apt install qpdfon Debian or Ubuntu.
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
- No prompt, still locked. A PDF with only an owner password opens for anyone. Its flags can block printing, copying or changes.
- OCRmyPDF read it. Both owner-only copies gave the control's text, with no warning.
- The limits were gone. pdfinfo said "Encrypted: no" on the output. OCRmyPDF first saves a work copy with pikepdf, and that copy has no encryption.
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
- OCR ran and found the control's words.
- The signature stays in the file, now broken. pdfsig says "Not total document signed", and pyHanko says INVALID.
- An empty signature box also stops OCRmyPDF: it reads a form flag, not the signature. The same flag works there and breaks nothing.
- If you sign it yourself, OCR first, then sign. That signature checked as valid. If someone else signed it, keep their file and OCR a copy.
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.
- Scanned pages: $0.006 each. Digital pages: free. Plus a $0.00005 start fee a run at the default 1 GB.
- On Apify's free plan, it stops at 20 pages a run and 50 a month.
What I did not test
- Files whose password I do not have. This page does not crack passwords.
- 40-bit RC4, and certificate (public key) encryption.
- How Acrobat and other readers show the broken signature. I checked with pdfsig and pyHanko only.
- Linux, Windows, and a Mac with Ghostscript. Without it, the signed output was a plain PDF, not PDF/A.
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
- OCRmyPDF docs
- qpdf command line (--decrypt, --encrypt)
- pikepdf docs
- pyHanko
- We make the Apify Actor, and none of the other tools here.
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.
Or send us the scan. Tack, our AI, does the job for $29, up to 50 pages. First page free.