830d9f2e4a
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
35 lines
1.9 KiB
Python
Vendored
35 lines
1.9 KiB
Python
Vendored
#!/usr/bin/env python3
|
|
"""Maakt van de dia's in project/slides één PDF (1920x1080 per pagina) met google-chrome.
|
|
|
|
Gebruik: python3 bouw_pdf.py (draait eerst maak_dias.py, dan Chrome headless)
|
|
Sprekersnotities (<aside>) komen niet in de PDF; die staan in project/slides/*.html.
|
|
"""
|
|
import json, subprocess, sys
|
|
from pathlib import Path
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
subprocess.run([sys.executable, str(HERE / "maak_dias.py")], check=True)
|
|
deck = json.loads((HERE / "project" / "deck.json").read_text(encoding="utf-8"))
|
|
faces = "".join(f'<link rel="stylesheet" href="{f["href"]}">' for f in deck["faces"].values())
|
|
css = """
|
|
@page { size: 1920px 1080px; margin: 0; }
|
|
html, body { margin: 0; padding: 0; }
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
section { position: relative; width: 1920px; height: 1080px; overflow: hidden; page-break-after: always; break-after: page; }
|
|
section:last-child { page-break-after: auto; }
|
|
aside { display: none; }
|
|
ul { padding-left: 1.1em; }
|
|
table { border-collapse: collapse; width: 100%; }
|
|
th, td { border: 1px solid #D8D2C4; padding: 12px 18px; text-align: left; vertical-align: top; }
|
|
img { max-width: 100%; }
|
|
"""
|
|
slides = "".join((HERE / "project" / "slides" / f"{sid}.html").read_text(encoding="utf-8") for sid in deck["order"])
|
|
html = (HERE / "project" / "alle-dias.html")
|
|
html.write_text(f'<!DOCTYPE html><html lang="nl"><head><meta charset="utf-8"><title>{deck["title"]}</title>'
|
|
f'{faces}<style>{css}</style></head><body>{slides}</body></html>', encoding="utf-8")
|
|
pdf = HERE / "presentatie-workshop-ai-agents.pdf"
|
|
subprocess.run(["google-chrome", "--headless=new", "--disable-gpu", "--no-pdf-header-footer",
|
|
"--virtual-time-budget=8000", f"--print-to-pdf={pdf}", html.as_uri()],
|
|
check=True, capture_output=True)
|
|
print(f"{pdf.name}: {pdf.stat().st_size // 1024} kB, {len(deck['order'])} dia's")
|