Render HTML or URL to PDF
TypeScriptToolsPOST api.upapi.io/html-to-pdf.postRender a public web page or a raw HTML document to a print-quality PDF with headless Chromium — paper size, orientation, margins, scale and page ranges included. Returns base64 PDF bytes.
Request schema
| Field | Type | Description |
|---|---|---|
url | string | Absolute http(s) URL to render (e.g. https://example.com). Mutually exclusive with html. URLs resolving to private, loopback, link-local or cloud-metadata addresses are rejected. |
html | string | Raw HTML document to render, up to 2 MB. Mutually exclusive with url. Relative asset paths cannot resolve in this mode — use absolute https URLs or inline/data: assets (e.g. <h1>Invoice #42</h1>). |
media | string | Which CSS media type to emulate. 'screen' (default) reproduces what a visitor sees; 'print' honours the site's print stylesheet (e.g. screen).· default: "screen" |
scale | number | Rendering scale of the webpage, 0.1 to 2 (e.g. 1).· default: 1 |
format | string | Paper size (e.g. A4).· default: "A4" |
margin | object | Page margins as CSS lengths. Omitted sides default to zero, matching Chromium (e.g. {"top":"1in","bottom":"1in"}). |
landscape | boolean | Print in landscape orientation instead of portrait (e.g. false).· default: false |
waitUntil | string | When rendering counts as done: 'domcontentloaded' is fastest, 'load' waits for subresources, 'networkidle' waits for the network to go quiet (e.g. load).· default: "load" |
pageRanges | string | Pages to include. Omit for the whole document (e.g. 1-5, 8). |
printBackground | boolean | Render background colours and images. Defaults to true — Chromium defaults this off, which strips the visual design most callers are trying to capture (e.g. true).· default: true |
Response schema
| Field | Type | Description |
|---|---|---|
pdfreq | string | Base64-encoded PDF bytes. No data: URI prefix — decode directly. |
bytesreq | integer | Size of the DECODED PDF in bytes (the base64 string is ~4/3 of this). |
pages | integer | Page count, read from the PDF itself. Omitted when the structure cannot be read with certainty — the PDF is still valid. |
Try it
Try it
Absolute http(s) URL to render (e.g. https://example.com). Mutually exclusive with html. URLs resolving to private, loopback, link-local or cloud-metadata addresses are rejected.
Raw HTML document to render, up to 2 MB. Mutually exclusive with url. Relative asset paths cannot resolve in this mode — use absolute https URLs or inline/data: assets (e.g. <h1>Invoice #42</h1>).
Which CSS media type to emulate. 'screen' (default) reproduces what a visitor sees; 'print' honours the site's print stylesheet (e.g. screen).
Rendering scale of the webpage, 0.1 to 2 (e.g. 1).
Paper size (e.g. A4).
Page margins as CSS lengths. Omitted sides default to zero, matching Chromium (e.g. {"top":"1in","bottom":"1in"}).
Print in landscape orientation instead of portrait (e.g. false).
When rendering counts as done: 'domcontentloaded' is fastest, 'load' waits for subresources, 'networkidle' waits for the network to go quiet (e.g. load).
Pages to include. Omit for the whole document (e.g. 1-5, 8).
Render background colours and images. Defaults to true — Chromium defaults this off, which strips the visual design most callers are trying to capture (e.g. true).
Run this endpoint live
Jump in as a guest — no signup — and run html-to-pdf.post with your own inputs. Create a free account anytime to get your own API key.
Code examples
curl -X POST https://api.upapi.io/html-to-pdf.post \
-H 'Content-Type: application/json' \
-H 'x-api-key: YOUR_API_KEY' \
-d '{ "url": "https://example.com", "media": "screen", "scale": 1, "format": "A4", "landscape": false, "waitUntil": "load", "printBackground": true }'