HTML to PDF API
Render HTML or URL to PDF turns a public web page or a raw HTML document into a PDF with headless Chromium and returns the file as a base64 string in a JSON response. Pass exactly one of url or html: a URL is fetched and rendered the way a visitor would see it, while html accepts a full document of up to 2 MB, which suits the invoices, reports and receipts you generate yourself. Layout is controlled with the options you would find in a print dialog — paper format A4, Letter or Legal, landscape or portrait, margins given as CSS lengths, a scale between 0.1 and 2, and pageRanges to keep only some of the pages. Background colours and images are printed by default, because switching them off strips the design most callers are trying to capture, and media chooses whether the page renders with its screen styles or its own print stylesheet. The response gives you the pdf, its decoded size in bytes and, when the structure can be read with certainty, the page count. In html mode relative asset paths cannot resolve, so reference absolute https URLs or inline your assets. A URL that resolves to a private, loopback, link-local or cloud-metadata address is rejected. Every call authenticates with your upAPI key. The exact price and cache lifetime are on this page’s FAQ, generated from the same catalog the calls run against.
What data you get
Render HTML or URL to PDF
- stringrequired — Base64-encoded PDF bytes. No
data:URI prefix — decode directly. - bytes
- integerrequired — 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.
Calling Render HTML or URL to PDF
A schema-derived request and response shape — not a captured production call, since upAPI has none to publish. Every field is real, from the operation’s own published schema.
curl -X POST https://api.upapi.io/html-to-pdf.post \
-H "X-Api-Key: $UPAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"media": "screen",
"scale": 1,
"format": "A4",
"landscape": false,
"waitUntil": "load",
"printBackground": true
}'{
"pdf": "example",
"bytes": 1,
"pages": 1
}Pricing
Every unit draws from one pooled monthly quota shared across the whole catalog. What a unit costs on each plan is on the pricing page, linked below.
Questions people actually ask
Can I convert an HTML string to PDF, not just a URL?
Yes. Send the html field with a complete document instead of a url — the two are mutually exclusive, and html can be up to 2 MB. Relative asset paths cannot resolve in that mode, so use absolute https URLs or inline assets.
How do I set the paper size, margins and orientation?
Use format for the paper size (A4, Letter or Legal), landscape for orientation, and margin for the four sides as CSS lengths such as 1in. A side you leave out defaults to zero, which matches Chromium.
Does the PDF keep background colours and images?
Yes, by default: printBackground is true, because Chromium’s own default of false strips the visual design. Set it to false if you want a plain print version.
How do I get the PDF out of the response?
The pdf field is the file as a base64 string with no data: prefix, so decode it directly and write the bytes to disk or object storage. The response also reports the decoded size in bytes and, when it can be read reliably, the number of pages.
How much does this cost?
Every operation in this cluster costs 20 weighted units per call, drawn from your plan’s pooled monthly quota — see upapi.io/pricing for what a unit costs on each tier.
How fresh is the data — is it cached?
every cached operation here returns a response held for 5 minutes. A repeat call inside a cached window returns the cached response and is billed nothing.
Related
Start with the free plan
One key and one pooled monthly quota cover Render HTML or URL to PDF and every other API in the catalog. See what a unit costs on each plan, or run the operation first.