html_to_pdf
Convert HTML files to PDF with print-aware styling, selectable Chromium or WeasyPrint rendering, color themes, and preserved clickable web and local links.
Instructions
Convert an HTML file (.html) to PDF with print-aware styling.
Supports two rendering engines:
- ``chromium`` (default): Uses Playwright headless Chromium. Pixel-identical
to Chrome Print → Save as PDF. Supports all modern CSS.
Requires: ``pip install playwright && playwright install chromium``.
- ``weasyprint``: Lightweight, good for simple documents.
Replaces emoji with font-styled spans. May not match Chrome perfectly
for display:flex / display:grid layouts.
Ordinary HTML keeps its original styles. Recognized portable analytics
reports receive a scoped A4 print profile for typography, cards, charts,
and source deduplication. Chromium also converts very wide tables to
labeled record cards. Three color themes are available: white for printing,
warm sepia for low-glare reading, and One Dark Pro for dark-room reading.
Preserves clickable web and local file links, including paths into other
repositories. Relative links respect the source directory or HTML base URL.
Call inspect_pdf_links first. Local Markdown/HTML links prefer verified
existing PDFs. Multiple editions require pdf_targets; references without
PDFs and other formats keep the source file. Only authored static anchors
are inspected; script-created links need an authored equivalent or review.
Args:
file_path: Absolute path to the .html file.
output_path: Absolute path for the output .pdf file.
If empty, derived from the source stem.
engine: Rendering backend: ``"chromium"`` or ``"weasyprint"``.
theme: Color theme: ``"print"`` (white, default), ``"sepia"``
(warm), or ``"one-dark-pro"`` (dark).
pdf_targets: Reviewed source-to-PDF paths, or null values to keep sources.
Relative paths resolve from the source directory.
pdf_destinations: Original hrefs mapped to fragments from resolve_pdf_destination.
link_policy: "prefer-pdf" selects existing PDFs; "preserve" keeps sources.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| theme | No | ||
| engine | No | chromium | |
| file_path | Yes | ||
| link_policy | No | prefer-pdf | |
| output_path | No | ||
| pdf_targets | No | ||
| pdf_destinations | No |