Files

17 lines
428 B
Python
Raw Permalink Normal View History

2026-07-16 11:12:17 +08:00
"""Document standardization for PDF input."""
from __future__ import annotations
from pathlib import Path
import fitz
def open_document(path: Path) -> fitz.Document:
"""Open and normalize a PDF for downstream layout processing."""
doc = fitz.open(path)
if doc.is_encrypted and not doc.authenticate(""):
doc.close()
raise ValueError(f"Encrypted PDF cannot be opened: {path.name}")
return doc