diff --git a/scripts/pdf_unlock.py b/scripts/pdf_unlock.py index dd2472d..ba7e29f 100644 --- a/scripts/pdf_unlock.py +++ b/scripts/pdf_unlock.py @@ -76,14 +76,21 @@ def isencrypted(pdf_name): Returns: True if encrypted, otherwise False + + Raises: + AttributeError if pdf info cannot be obtained """ - pdf_info = pdfinfo(pdf_name) - status = pdf_info['Encrypted'].split(' ')[0] - - if status == 'yes': - return True - else: - return False + try: + pdf_info = pdfinfo(pdf_name) + status = pdf_info['Encrypted'].split(' ')[0] + if status == 'yes': + return True + elif status == 'no': + return False + else: + raise ValueError + except (SyntaxError, KeyError, ValueError): + raise AttributeError('Could not read pdf info.') def pdf_unlock(pdf_file, overwrite=False):