from pathlib import Path
import pymupdf

source = Path("document.pdf")
output = Path("output")

with pymupdf.open(source) as document:
    if document.needs_pass:
        raise ValueError("Unlock the PDF before converting it.")
    output.mkdir(exist_ok=False)
    for number, page in enumerate(document, start=1):
        image = page.get_pixmap(dpi=144, alpha=False)
        image.save(output / f"page-{number:03d}.png")
