MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / open_file

Function open_file

src/__main__.py:57–76  ·  view source on GitHub ↗

Open and authenticate a document.

(filename, password, show=False, pdf=True)

Source from the content-addressed store, hash-verified

55
56
57def 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
79def print_dict(item):

Callers 11

showFunction · 0.70
cleanFunction · 0.70
doc_joinFunction · 0.70
embedded_copyFunction · 0.70
embedded_delFunction · 0.70
embedded_getFunction · 0.70
embedded_addFunction · 0.70
embedded_updFunction · 0.70
embedded_listFunction · 0.70
extract_objectsFunction · 0.70
gettextFunction · 0.70

Calls 1

authenticateMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…