# Render HTML or URL to PDF API

> 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, or a signed link with output: url.

Category: [Tools APIs](https://upapi.io/apis/tools) · Last updated 2026-11-10

## How to call it

- Endpoint: `POST https://api.upapi.io/html-to-pdf.post`, key in the `X-Api-Key` header, JSON body.
- Cost: 20 weighted units per call.
- Timeout: 25 seconds.
- Cache: identical requests are served from cache for 300 seconds, unbilled.
- Try it without writing code: https://app.upapi.io/try/html-to-pdf.post

```bash
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", "output": "base64", "landscape": false, "waitUntil": "load", "printBackground": true }'
```

## Request parameters

- `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` (enum) — Which CSS media type to emulate. 'screen' (default) reproduces what a visitor sees; 'print' honours the site's print stylesheet (e.g. screen).
- `scale` (number) — Rendering scale of the webpage, 0.1 to 2 (e.g. 1).
- `format` (enum) — Paper size (e.g. A4).
- `margin` (object) — Page margins as CSS lengths. Omitted sides default to zero, matching Chromium (e.g. {"top":"1in","bottom":"1in"}).
- `margin.top` (string) — Top margin (e.g. 1in).
- `margin.left` (object) — Left margin (e.g. 0.5in).
- `margin.right` (object) — Right margin (e.g. 0.5in).
- `margin.bottom` (object) — Bottom margin (e.g. 1in).
- `output` (enum) — How the file comes back: 'base64' (default) puts the bytes in the response; 'url' returns `fileUrl`, a signed HTTPS link that expires after 1 hour, instead — for no-code tools such as Bubble that save a file from a URL (e.g. base64).
- `landscape` (boolean) — Print in landscape orientation instead of portrait (e.g. false).
- `waitUntil` (enum) — When rendering counts as done: 'domcontentloaded' is fastest, 'load' waits for subresources, 'networkidle' waits for the network to go quiet (e.g. 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).

## Response fields

- `pdf` (string) — Base64-encoded PDF bytes. No `data:` URI prefix — decode directly. Present when `output` is 'base64' (the default); replaced by `fileUrl` in url mode.
- `bytes` (integer, required) — 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.
- `fileUrl` (string) — Signed HTTPS link to the file, present only when `output` was 'url'. It expires after 1 hour and the file is deleted soon after.
- `fileUrlExpiresAt` (string) — When `fileUrl` stops working, as an ISO 8601 timestamp. Only when `output` was 'url'.

## Example request and response

The example response is generated from the published output schema: it shows the shape and field names, not values from a recorded call.

```json
{
  "url": "https://example.com",
  "media": "screen",
  "scale": 1,
  "format": "A4",
  "output": "base64",
  "landscape": false,
  "waitUntil": "load",
  "printBackground": true
}
```

```json
{
  "pdf": "example",
  "bytes": 1,
  "pages": 1,
  "fileUrl": "example",
  "fileUrlExpiresAt": "example"
}
```

## Frequently asked questions

### How much does the Render HTML or URL to PDF API cost per call?

Each call spends 20 weighted units of your plan's monthly quota. Full pricing is at https://upapi.io/pricing.

### How do I authenticate to the Render HTML or URL to PDF API?

Send your key in the X-Api-Key header. A free guest key is available without creating an account.

### Are Render HTML or URL to PDF API responses cached?

Yes — identical requests are served from cache for 300 seconds, and a cache hit is not billed.

## More Tools APIs

- [Capture Website Screenshot](https://upapi.io/apis/tools/screenshot)
- [Extract Text from PDF](https://upapi.io/apis/tools/pdf-extract-text)
- [Fetch URL as Markdown](https://upapi.io/apis/tools/fetch-markdown)
- [OCR an Image](https://upapi.io/apis/tools/image-ocr)
- [Search Hacker News](https://upapi.io/apis/tools/hackernews-search)
- [Get Cloudflare Page Title](https://upapi.io/apis/tools/cloudflare-page-title)
