html_to_pdf
Render HTML documents into PDF files using headless Chromium, supporting full CSS, inline SVG, and print-media queries. Use for invoices, reports, and certificates.
Instructions
Convert an HTML document to a PDF and return it as a base64-encoded string.
Renders the HTML in a headless Chromium browser and exports to PDF.
Supports full CSS (including Flexbox, Grid, custom fonts via Google Fonts),
inline SVG, and print-media-query styles. Page size defaults to A4.
Use for generating invoices, reports, certificates, or any document that
needs to be rendered exactly as it appears in a browser.
Args:
html: Complete HTML document to convert. Should include a full
<html><head>...</head><body>...</body></html> structure.
For best results include a <style> block or link to a CDN CSS.
Use @media print CSS rules to control page breaks.
Returns:
Base64-encoded PDF bytes. Decode with base64.b64decode() to get the
raw PDF binary, which can be written to a file or returned to a user.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| html | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |