From 31a032e5c9f5fc8e36af83443ee1620fefd68ca2 Mon Sep 17 00:00:00 2001 From: pivotman Date: Tue, 16 Nov 2021 20:53:03 +1300 Subject: [PATCH] Update iohelper.py Some PDFs are tagged as encrypted, even though they aren't encrypted, and will open without a password prompt in a GUI PDF reader. This change attempts to "decrypt" with a blank password, before prompting for a password. --- staplelib/iohelper.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/staplelib/iohelper.py b/staplelib/iohelper.py index 959e900..0007bd9 100644 --- a/staplelib/iohelper.py +++ b/staplelib/iohelper.py @@ -33,12 +33,11 @@ def read_pdf(filename): raise CommandError("{} does not exist".format(filename)) pdf = PdfFileReader(open(filename, "rb")) if pdf.isEncrypted: - while True: + matched = pdf.decrypt('') + while not matched: pw = prompt_for_pw(filename) matched = pdf.decrypt(pw) - if matched: - break - else: + if not matched: print("The password did not match.") return pdf