import fitz  # PyMuPDF
from pdf2image import convert_from_path
import os

POPPLER_PATH = os.getenv("POPPLER_PATH", r"C:\poppler\bin")

def pdf_to_images(pdf_path: str, output_dir: str):
    """Convert all PDF pages to PNG images"""
    os.makedirs(output_dir, exist_ok=True)
    images = convert_from_path(pdf_path, poppler_path=POPPLER_PATH)
    paths = []
    for i, img in enumerate(images, start=1):
        out_path = os.path.join(output_dir, f"{os.path.basename(pdf_path)}_page_{i}.png")
        img.save(out_path, "PNG")
        paths.append(out_path)
    return paths
