Open and authenticate a document.
(filename, password, show=False, pdf=True)
| 55 | |
| 56 | |
| 57 | def open_file(filename, password, show=False, pdf=True): |
| 58 | """Open and authenticate a document.""" |
| 59 | doc = pymupdf.open(filename) |
| 60 | if not doc.is_pdf and pdf is True: |
| 61 | sys.exit("this command supports PDF files only") |
| 62 | rc = -1 |
| 63 | if not doc.needs_pass: |
| 64 | return doc |
| 65 | if password: |
| 66 | rc = doc.authenticate(password) |
| 67 | if not rc: |
| 68 | sys.exit("authentication unsuccessful") |
| 69 | if show is True: |
| 70 | auth_level = "user" |
| 71 | if rc > 2: |
| 72 | auth_level = "owner" |
| 73 | pymupdf.message(f"authenticated as {auth_level}") |
| 74 | else: |
| 75 | sys.exit(f"'{doc.name}' requires a password") |
| 76 | return doc |
| 77 | |
| 78 | |
| 79 | def print_dict(item): |
no test coverage detected
searching dependent graphs…