mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-12-02 20:20:35 -05:00
Verify protected documents disable Print before opening the dialog
This commit is contained in:
1 parent
0de75e1642
commit
d231907ce3
1 file changed
+11
-22
@@ -95,13 +95,6 @@ def choose_print(driver, selected=None):
|
||||
subprocess.run(["xdotool", "mousemove", "1080", "996", "click", "1"], check=True)
|
||||
|
||||
|
||||
def recognize(image):
|
||||
encoded = io.BytesIO()
|
||||
image.save(encoded, format="PNG")
|
||||
return subprocess.check_output(
|
||||
["tesseract", "stdin", "stdout", "--psm", "11"], input=encoded.getvalue()).decode()
|
||||
|
||||
|
||||
def preview(name, color):
|
||||
deadline = time.monotonic() + 55
|
||||
while True:
|
||||
@@ -165,21 +158,17 @@ def verify_pdf(path):
|
||||
|
||||
|
||||
def denied_print(driver):
|
||||
choose_print(driver)
|
||||
deadline = time.monotonic() + 15
|
||||
while True:
|
||||
screenshot = ImageGrab.grab()
|
||||
words = recognize(screenshot).replace("’", "'")
|
||||
if "don't allow printing" in " ".join(words.lower().split()):
|
||||
screenshot.save(RESULTS / "print-denied.png")
|
||||
(RESULTS / "print-denied.txt").write_text(words)
|
||||
assert not driver.execute_script("return !!document.querySelector('iframe[srcdoc]')")
|
||||
assert len(pdf_files()) == 1
|
||||
print("PdfCraft reported that the document's security settings don't allow printing", flush=True)
|
||||
return
|
||||
if time.monotonic() > deadline:
|
||||
raise TimeoutError(words)
|
||||
time.sleep(0.35)
|
||||
state = result(driver, "ui.state")
|
||||
assert any(doc["active"] and doc["name"] == "none.pdf" and doc["pages"] == 3 for doc in state["documents"]), state
|
||||
before = pdf_files()
|
||||
assert len(before) == 1
|
||||
refusal = command(driver, "ui.command", {"id": "print.dialog"})
|
||||
assert not refusal["ok"] and "print.dialog is disabled" in refusal["error"], refusal
|
||||
(RESULTS / "print-denied.json").write_text(json.dumps(refusal, indent=2))
|
||||
assert not driver.execute_script("return !!document.querySelector('iframe[srcdoc]')")
|
||||
assert pdf_files() == before
|
||||
ImageGrab.grab().save(RESULTS / "print-denied.png")
|
||||
print("Print was disabled for the open three-page document that permits no printing", flush=True)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in new issue
Block a user