diff --git a/ocrmypdf/qpdf.py b/ocrmypdf/qpdf.py index b214504d..7d88e1f0 100644 --- a/ocrmypdf/qpdf.py +++ b/ocrmypdf/qpdf.py @@ -45,7 +45,11 @@ def repair(input_file, output_file, log): print(e.output) return - if e.returncode == 2: + if e.returncode == 2 and e.output.find("invalid password"): + print("{0}: this PDF is password-protected - password must " + "be removed for OCR".format(input_file)) + sys.exit(ExitCode.input_file) + elif e.returncode == 2: print("{0}: not a valid PDF, and could not repair it.".format( input_file)) print("Details:") diff --git a/tests/resources/skew-encrypted.pdf b/tests/resources/skew-encrypted.pdf new file mode 100644 index 00000000..2a8fb769 Binary files /dev/null and b/tests/resources/skew-encrypted.pdf differ diff --git a/tests/test_main.py b/tests/test_main.py index b91b04d5..d4c9a76a 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -317,3 +317,9 @@ def test_qpdf_repair_fails(): print(out) print(err) assert p.returncode == ExitCode.input_file + + +def test_encrypted(): + p, out, err = run_ocrmypdf_env('skew-encrypted.pdf', 'wont_be_created.pdf') + assert p.returncode == ExitCode.input_file + assert out.find('password')