Convert HTML to PDF via headless Chrome. Zero Python dependencies.
Built for AI agents, research pipelines, and automated report generation.
html2pdf input.html # → input.pdf
html2pdf input.html -o report.pdf # → report.pdf
html2pdf input.html --base64 # → base64 to stdout
html2pdf https://example.com -o page.pdf # URL input
Don't have Chrome infrastructure? html2pdf comes pre-installed in the NexusBrowser MCP sandbox. One MCP connection gives your agent headless Chrome, 34 research tools, and html2pdf — zero setup. See Agent Skill Guide.
This 8-page commodity research report was generated end-to-end by an AI agent
using html2pdf and the NexusBrowser MCP
server for live web research. No human wrote the HTML, gathered the data, or
ran the commands — the agent did everything from research to final PDF.
| Cover | Executive Summary |
|---|---|
![]() |
![]() |
| SVG Charts & Analysis | Price Projections |
|---|---|
![]() |
![]() |
Full example: examples/silver-report/ — HTML source,
generated PDF, page screenshots, and a HOWTO
explaining the pipeline.
1. RESEARCH — Browse live sources via NexusBrowser MCP
├── Dillon Gage (Dallas) → live precious metals spot ticker
├── Kitco → bid/ask spreads, day range, news headlines
└── Trading Economics → forecasts, YoY data, analyst notes
2. COMPOSE — Write HTML with print CSS and inline SVG charts
├── Cover page with styled price banner
├── Data tables (spot snapshot, precious metals complex, macro factors)
├── 4 inline SVG charts (12-month, intraday, supply/demand, projections)
├── Scenario analysis tables with color-coded rows
└── @page CSS, break rules, two-column layouts
3. GENERATE — html2pdf renders the final PDF
$ html2pdf report.html --output report.pdf --no-header --paper a4
→ 8 pages, 366 KB, all charts and styling preserved
No Puppeteer, no Node.js, no wkhtmltopdf. Just Python 3 and Chrome.
- Python 3.9+
- Google Chrome or Chromium on PATH
pip install html2pdf-cliOr copy the single html2pdf script anywhere on your PATH:
curl -o /usr/local/bin/html2pdf https://raw.githubusercontent.com/Spitfire-Products/html2pdf-cli/main/html2pdf
chmod +x /usr/local/bin/html2pdfhtml2pdf input.html # → input.pdf (same dir)
html2pdf input.html -o report.pdf # → report.pdf
html2pdf input.html --base64 # → base64 string to stdout
html2pdf https://example.com -o page.pdf # URL input
html2pdf input.html --paper a4 # paper size (default: a4)
html2pdf input.html --paper letter
html2pdf input.html --landscape # landscape orientation
html2pdf input.html --no-header # suppress Chrome header/footer
html2pdf input.html --margins "25mm 20mm" # custom margins via @page CSS
html2pdf input.html --fetch-images # download remote <img src>
html2pdf input.html --timeout 60 # Chrome timeout (default: 30s)
html2pdf input.html --inject-css style.css # inject CSS before render
html2pdf input.html --scale 1.5 # print scale factor
html2pdf input.html --chrome /path/to/chrome # explicit Chrome binary
Built-in: a3, a4, a5, letter, legal, tabloid
Custom: --paper 11x17 (width x height in inches)
--base64 prints the PDF as a base64 string to stdout, with size and token
estimate to stderr. Useful for piping into tools that accept base64 input:
html2pdf report.html --base64 --no-header | my-upload-tool --stdin--fetch-images downloads <img src="https://..."> images to a temp
directory and rewrites the HTML to use local references before rendering.
This ensures images appear even when Chrome can't reach the network.
For containers that already have Chrome installed:
COPY html2pdf /usr/local/bin/html2pdf
RUN chmod +x /usr/local/bin/html2pdfThe script auto-detects Chrome as google-chrome-stable, google-chrome,
chromium-browser, or chromium.
html2pdf is designed to work standalone — bring your own Chrome. But if you want the full pipeline (deep web research + data extraction + PDF generation) without managing browser infrastructure, the NexusBrowser MCP server gives your agent everything in a single connection:
- 34 browser tools — browse, scrape, screenshot, interact, solve CAPTCHAs
- Sandboxed shell —
run_commandfor curl, file I/O, and html2pdf - html2pdf pre-installed — generate PDFs immediately, no setup
- Stealth browsing — fingerprint spoofing, human-like interaction, challenge solving
See docs/AGENT_SKILL.md for a drop-in skill definition
that teaches any MCP-compatible agent to go from a research prompt to a
publication-quality PDF report. The silver report example
demonstrates the complete pipeline — an agent that researched live commodity data
from Dillon Gage, Kitco, and Trading Economics, composed an 8-page report with
SVG charts, and generated the PDF in under 3 minutes.
html2pdf is a thin wrapper around Chrome's --print-to-pdf flag. It handles:
- Paper size translation to
--paper-width/--paper-height(inches) - Landscape orientation (swaps width/height)
- Margin injection via
@pageCSS (Chrome has no native margin flag) - Remote image downloading for offline renders
- CSS injection before render
- URL-to-local-file resolution
- Base64 encoding with token cost reporting
No Puppeteer, no Node.js, no pip dependencies. Just Python 3 and Chrome.
MIT



