#!/usr/bin/env python3 """render_check.py — rasterize PDF pages to PNG for visual verification. Cross-platform: uses pypdfium2 (already pulled in with pdfplumber), so it needs no poppler/pdftoppm. On Windows this is the practical way to do the "ALWAYS verify visually" step from SKILL.md. Usage: python render_check.py Output.pdf # every page -> Output_p1.png, ... python render_check.py Output.pdf 1 2 5 # only pages 1, 2, 5 (1-based) python render_check.py Output.pdf 1 2 --scale 2 # higher resolution """ import sys, pathlib try: import pypdfium2 as pdfium except Exception: sys.exit("Missing pypdfium2 (it installs alongside pdfplumber).\n" " pip install pypdfium2") def main(): args = list(sys.argv[1:]) if not args: sys.exit("Usage: python render_check.py [pages...] [--scale N]") scale = 1.5 if "--scale" in args: i = args.index("--scale") try: scale = float(args[i + 1]) except (IndexError, ValueError): sys.exit("--scale needs a number, e.g. --scale 2") del args[i:i + 2] pdf_path = args[0] if not pathlib.Path(pdf_path).exists(): sys.exit(f"PDF not found: {pdf_path}") pages = [int(a) for a in args[1:]] pdf = pdfium.PdfDocument(pdf_path) n = len(pdf) idxs = [p - 1 for p in pages] if pages else range(n) stem = pathlib.Path(pdf_path).with_suffix("") for i in idxs: if i < 0 or i >= n: print(f" ! page {i + 1} out of range (1..{n})") continue out = f"{stem}_p{i + 1}.png" pdf[i].render(scale=scale).to_pil().save(out) print("wrote", out) if __name__ == "__main__": main()