# HTML to PDF API: convert a URL to PDF with one request

> Convert a web page to PDF with one HTTP request: curl and Node.js examples, paper sizes, one continuous page, errors and limits. Takes a URL, not raw HTML.

By [Mayur Gadakh](https://urlbooth.com/about) · Published 2026-11-23 · Last updated 2026-11-23

Send a POST request to `/v1/screenshots` with `"format": "pdf"` and a public URL, and the response body is the PDF. It converts a live web page, not an HTML string: to convert HTML you have, host it at a public URL first.

## How do I convert a URL to PDF with curl?

URL to PDF with curl

```bash
curl --fail-with-body "https://urlbooth.com/v1/screenshots" \
  -H "Authorization: Bearer $URLBOOTH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com","format":"pdf","paper":"a4","printBackground":true}' \
  -o page.pdf
```

You need a Pro API key (see [pricing](https://urlbooth.com/pricing)). The `paper` field is `letter`, `a4`, `legal` or `a3`. Leave it out to get one continuous page as wide as the device and as tall as the page, so nothing is split.

## How do I convert a URL to PDF in Node.js?

URL to PDF in Node.js

```js
import { writeFile } from "node:fs/promises";

const response = await fetch("https://urlbooth.com/v1/screenshots", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.URLBOOTH_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ url: "https://example.com", format: "pdf", paper: "a4" }),
  signal: AbortSignal.timeout(60_000),
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message}`);
}

await writeFile("page.pdf", Buffer.from(await response.arrayBuffer()));
```

This uses the built-in `fetch` in Node 18 or later. Errors come back as JSON with a `code`, a `message` and a `requestId`.

## Which options does the PDF API take?

- `url` (required): a public http or https page.
- `format`: `pdf`.
- `paper`: `letter`, `a4`, `legal` or `a3`. Without it, one continuous page.
- `printBackground` (default true): include background colours and images.
- `device` (default desktop): the viewport the page is laid out at, for example `iphone-17-pro` for the mobile layout.
- `cleanup` (default true): remove cookie banners and ads, best effort.

## What are the limits and errors?

- The PDF must be 25 MB or smaller, otherwise the request fails with 422 `image_too_large`. Try `printBackground: false` or a paper size.
- A continuous page taller than 40,000 pixels fails with 422 `page_too_large`; set `paper` to split it into pages.
- Requests time out after about 45 seconds. Pro allows 60 requests a minute and 10 at once; extra requests return 429.
- Only public pages are fetched, and sites that block automated browsers may return an error or a challenge page.

Every error code is listed in the [API reference](https://urlbooth.com/docs). To try it without code, use the free [save a webpage as PDF tool](https://urlbooth.com/tools/save-webpage-as-pdf).

## Where to go next

- [Playwright PDF](https://urlbooth.com/guides/playwright-pdf)
- [Puppeteer PDF](https://urlbooth.com/guides/puppeteer-pdf)
- [Screenshot API vs Puppeteer and Playwright](https://urlbooth.com/guides/screenshot-api-vs-puppeteer)

## Related guides

- [wkhtmltopdf alternatives](https://urlbooth.com/guides/wkhtmltopdf-alternatives)

  Why wkhtmltopdf is a dead end, how headless Chrome, Puppeteer, Gotenberg, WeasyPrint and Prince compare, and a flag-by-flag port.
- [Puppeteer PDF: generate a PDF from a web page](https://urlbooth.com/guides/puppeteer-pdf)

  page.pdf() code for Node.js, paper sizes, backgrounds, common problems and fixes, and the same PDF from one API request.
- [Playwright PDF: save a web page as PDF](https://urlbooth.com/guides/playwright-pdf)

  page.pdf() code, why the PDF looks different from the screen, backgrounds and page breaks, and the one-request alternative.
- [Free tool: website to PDF](https://urlbooth.com/tools/website-to-pdf)

  Convert any public URL to a PDF with selectable text and working links.

---

Source: https://urlbooth.com/guides/html-to-pdf-api
