# CREATE — Generate a New PDF > **Prerequisites.** Read [`html-pdf-spec.md`](html-pdf-spec.md) for the > mechanical contract (page geometry, page-break rules, Chart.js settle, CJK > cascade). Read [`design-guide.md`](design-guide.md) for the aesthetic > contract (palette mood, typography, anti-patterns). This file is the > end-to-end recipe that ties them together. The CREATE pipeline has one shape: ``` HTML file (templates//skeleton.html or hand-written) └─► render_html.cjs (Playwright Chromium) └─► report.pdf ``` There is no token system, no ReportLab, no LaTeX. If a primitive cannot be expressed in HTML+CSS+JS, it does not belong in CREATE. --- ## 1. The 4 steps ```bash # Step 1 — verify deps once per machine bash scripts/make.sh check # Step 2 — pick a starting point (DO NOT skip this scan) cat templates/INDEX.md cat templates//README.md # 7-section recipe # Step 3 — copy the skeleton, fill the placeholders, re-skin to your topic cp templates//skeleton.html /tmp/work/page.html $EDITOR /tmp/work/page.html # Step 4 — render & verify bash scripts/make.sh render --in /tmp/work/page.html --out /tmp/work/out.pdf --wait 15000 pdfinfo /tmp/work/out.pdf | grep Pages pdftotext -layout /tmp/work/out.pdf - | head -40 open /tmp/work/out.pdf # eyeball it ``` The `--wait 15000` flag is critical when the page contains Chart.js or any late-loading JS. Static prose can use the default `--wait 800`. See [html-pdf-spec.md §6](html-pdf-spec.md#6-charts-chartjs). --- ## 2. Picking a template [`templates/INDEX.md`](../templates/INDEX.md) lists every skeleton with intent keywords. Match by user intent first, then by document shape: | Intent | Template | |---|---| | Restaurant menu, bilingual omakase | `bilingual-menu-premium` | | Brand guide / style guide / 2-page identity | `brand-guide-2page` | | Data report / benchmark / 数据可视化 / 评测 | `data-viz-report` | | Article digest / blog anthology / newsletter | `multi-article-aggregator` | | Multi-country research / regulatory survey | `multilang-research-report` (for AI voice cloning / legal-regulatory surveys, read `docs/ai-voice-cloning-regulatory-report-case.md`) | | Plain markdown report (REFORMAT path) | `reformat-default` | If nothing fits, **adapt the closest** rather than starting from scratch — the skeletons encode page-break math and CJK cascades that take real time to get right. If the user's content is genuinely unique (not just "reskin needed"), hand-author the HTML following [`html-pdf-spec.md`](html-pdf-spec.md) and copy individual primitives (KPI cards, chart cards, pill table) from `templates/data-viz-report/skeleton.html`. --- ## 2. JSON-driven CREATE workflow (data reports) Use this when the PDF is a data/report deliverable and the content should be separated from layout. The contract is still **HTML → Playwright → PDF**; JSON is only an intermediate content manifest consumed by your build script. ### 2.1 Minimal `content.json` shape Always write JSON with `json.dumps(..., ensure_ascii=False, indent=2)` — never hand-concatenate strings. ```json { "meta": { "title": "2024 Annual Report Digest", "subtitle": "Financial highlights and segment revenue", "author": "Mavis", "date": "2026-04-26", "locale": "zh-CN", "page_format": "A4", "style": "print-academic" }, "theme": { "accent": "#8A1E1E", "ink": "#1F2A25", "muted": "#66706A", "paper": "#FBFAF7" }, "kpis": [ {"label": "营业收入", "value": "2.94万亿", "delta": "同比 -2.5%", "tone": "neutral"}, {"label": "归母净利润", "value": "1,646.84亿", "delta": "同比 +2.0%", "tone": "good"} ], "sections": [ { "id": "financials", "title": "主要财务指标", "lead": "单位除特别注明外为人民币百万元。", "tables": [ { "caption": "近五年主要财务指标", "columns": ["项目", "2024", "2023", "2022"], "rows": [ ["营业收入", "2,937,981", "3,012,812", "3,240,951"], ["净利润", "183,755", "180,563", "163,493"] ], "source": "年报第5页" } ], "charts": [ {"id": "trend", "title": "财务趋势", "image": "trend.png", "alt": "五年收入与利润趋势"} ], "takeaways": ["收入同比回落,但利润端保持韧性。"] } ], "footnotes": [ "本摘要不替代经审计年度报告全文。" ] } ``` Recommended fields: | Field | Required | Meaning | |---|---:|---| | `meta.title` | yes | Cover/title-bar title; must match user language. | | `meta.page_format` | yes | Usually `A4`; renderer must also pass `--format A4`. | | `theme.*` | no | Palette tokens copied into CSS variables. | | `kpis[]` | no | Small KPI cards; values are strings so units are explicit. | | `sections[].tables[]` | no | Dense source tables; keep `source` for auditability. | | `sections[].charts[]` | no | Static image paths or data-URI strings; runtime chart libraries are optional but static PNGs are preferred for strict deliverables. | | `sections[].takeaways[]` | no | Short bullets; do not let prose crowd out tables. | | `footnotes[]` | no | Method, caveats, and source notes. | ### 2.2 Build script skeleton This script turns `content.json` into `page.html`. Keep HTML escaping explicit; never paste JSON directly into JavaScript unless you serialized it yourself. ```python import html, json from pathlib import Path work = Path("/tmp/pdf-create") payload = json.loads((work / "content.json").read_text(encoding="utf-8")) def esc(x): return html.escape(str(x), quote=True) def render_table(table): head = "".join(f"{esc(c)}" for c in table["columns"]) rows = [] for row in table["rows"]: rows.append("" + "".join(f"{esc(c)}" for c in row) + "") source = f"
{esc(table.get('source',''))}
" if table.get("source") else "" return f"
{esc(table['caption'])}
{head}{''.join(rows)}
{source}
" sections = [] for sec in payload["sections"]: body = [f"
", f"

{esc(sec['title'])}

"] if sec.get("lead"): body.append(f"

{esc(sec['lead'])}

") for table in sec.get("tables", []): body.append(render_table(table)) for chart in sec.get("charts", []): body.append(f"
{esc(chart.get(
{esc(chart['title'])}
") for item in sec.get("takeaways", []): body.append(f"

{esc(item)}

") body.append("
") sections.append("\n".join(body)) html_doc = f""" {esc(payload['meta']['title'])} {''.join(sections)} """ (work / "page.html").write_text(html_doc, encoding="utf-8") ``` ### 2.3 End-to-end commands ```bash SKILL=/path/to/pdf WORK=/tmp/pdf-create mkdir -p "$WORK" bash "$SKILL/scripts/make.sh" check python3 "$WORK/build_content.py" # writes content.json and any chart PNGs python3 "$WORK/build_html.py" # content.json -> page.html bash "$SKILL/scripts/make.sh" render \ --in "$WORK/page.html" \ --out "$WORK/report.pdf" \ --format A4 \ --wait 15000 pdfinfo "$WORK/report.pdf" | grep -E "Pages|Page size" pdfimages -list "$WORK/report.pdf" | tail -n +3 | wc -l pdftotext -layout "$WORK/report.pdf" - | head -40 ``` Expected evidence: - `Page size` is A4. - `Pages` matches the requested cap. - image count is at least the number of embedded chart PNGs/logos. - `pdftotext` shows readable body text and key figures. - Source HTML and `content.json` have no placeholder tokens. --- ## 3. The component primitive cookbook Every primitive below ships in `templates/data-viz-report/skeleton.html` (self-contained). Copy the markup + CSS for the ones you need. ### Cover (full-bleed gradient) ```html
DEEP RESEARCH · 2026

Report title

One-sentence positioning, ≤ 3 lines.

14
CHIPS
...
RESEARCH REPORT
v1.0 · 2026/04
``` ### Section header (eyebrow + H2 + accent rule) ```html PART 01 · 硬件分析

Apple M-series Hardware Analysis

``` ### KPI 4-grid (4 color variants) ```html
Q3
$4.2M
vs $3.1M Q2
…
…
…
``` ### Chart card (always wrap with `.avoid-break`) ```html
Figure 1.1 · Memory bandwidth & TOPS evolution
Max series M1 → M4 representative comparison
``` ### Reference table with status pills ```html
ChipMemoryVerdict
M3 Pro36 GB✓ Feasible
M4 Max128 GB★★ Excellent
``` 5 pill semantics are fixed: `bad / warn / ok / good / best`. Do not invent new colors. ### Versus comparison ```html
APPLE M4 MAX

Unified memory · End-of-line

  • ...
VS
NVIDIA RTX 5090

CUDA empire · Compute beast

  • ...
``` ### Recommend triple (entry / recommended / premium) ```html
Entry...
★ Recommended...
Premium...
``` ### Insight callout (yellow, one paragraph) ```html
⚡ Key insight Body text — one paragraph, ideally a single takeaway. Don't stack 3 of these on a page.
``` ### Dark conclusion block ```html

01.Title of the conclusion

Body text on dark background. Keep it short.

``` ### Chart.js initialization (8 baseline types) See `templates/data-viz-report/skeleton.html` `