17 lines
428 B
Python
17 lines
428 B
Python
"""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
|