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

By Mayur Gadakh · Published · Last updated

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
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). 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
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. To try it without code, use the free save a webpage as PDF tool.

Where to go next