Files
dify-guides/00-presentation/build_pdf.py
T
Guido van Dijk 180361eda4 Dify guides: first release, English set, 20 September 2026
Eight step-by-step guides, appendices (design patterns, design card with eight
filled-in examples, AI tools in education), facilitator guide and presentation.
LeX Consultancy edition; screenshots from the Dutch build of the same apps.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 23:09:39 +02:00

35 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""Turns the slides in project/slides into one PDF (1920x1080 per page) with google-chrome.
Usage: python3 build_pdf.py (runs make_slides.py first, then Chrome headless)
Speaker notes (<aside>) are not in the PDF; they are in project/slides/*.html.
"""
import json, subprocess, sys
from pathlib import Path
HERE = Path(__file__).resolve().parent
subprocess.run([sys.executable, str(HERE / "make_slides.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" / "all-slides.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 / "presentation-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'])} slides")