Render HTML or URL to PDF

TypeScriptTools
POST api.upapi.io/html-to-pdf.post

Render 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.

pdfhtmlbrowserrenderprintdocument
AuthAPI key
Cost20 units
Timeout25s
Cache300s

Request schema

FieldTypeDescription
url
stringAbsolute 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
stringRaw 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
stringWhich 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
numberRendering scale of the webpage, 0.1 to 2 (e.g. 1).· default: 1
format
stringPaper size (e.g. A4).· default: "A4"
margin
objectPage margins as CSS lengths. Omitted sides default to zero, matching Chromium (e.g. {"top":"1in","bottom":"1in"}).
landscape
booleanPrint in landscape orientation instead of portrait (e.g. false).· default: false
waitUntil
stringWhen 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
stringPages to include. Omit for the whole document (e.g. 1-5, 8).
printBackground
booleanRender 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

FieldTypeDescription
pdfreq
stringBase64-encoded PDF bytes. No data: URI prefix — decode directly.
bytesreq
integerSize of the DECODED PDF in bytes (the base64 string is ~4/3 of this).
pages
integerPage 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.

Sign in

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 }'

Developer tools

OpenAPI specImport the spec or collection into Postman, Insomnia, or any codegen tool.