import os, subprocess

edge_path = r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'

html_sample = """<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
  @page { size: letter; margin: 0.5in; }
  body { font-family: Arial, sans-serif; }
  h1 { color: #1e3a8a; }
</style>
</head>
<body>
  <h1>1:12 Scale Dollhouse Architectural Plans</h1>
  <p>Test PDF generation using Microsoft Edge headless.</p>
</body>
</html>"""

with open("test_page.html", "w", encoding="utf-8") as f:
    f.write(html_sample)

pdf_out = os.path.abspath("test_out.pdf")
cmd = [
    edge_path,
    "--headless",
    "--disable-gpu",
    "--run-all-compositor-stages-before-draw",
    f"--print-to-pdf={pdf_out}",
    "--no-pdf-header-footer",
    os.path.abspath("test_page.html")
]

res = subprocess.run(cmd, capture_output=True, text=True)
print("Return code:", res.returncode)
print("PDF exists:", os.path.exists(pdf_out), "Size:", os.path.getsize(pdf_out) if os.path.exists(pdf_out) else 0)
