Print any page to a PDF, the way Chrome's Save as PDF does.
POST /v1/pdf opens a URL in a fresh browser and prints it to PDF, the way Chrome’s Save as PDF does. The response body is the PDF.
Request
curl -X POST https://api.boxline.dev/v1/pdf \ -H "x-api-key: $BOXLINE_API_KEY" \ -H "content-type: application/json" \ -d '{"url": "https://example.com", "paper": "Letter"}' \ -o page.pdfimport { writeFile } from "node:fs/promises";const pdf = await bx.pdf("https://example.com", { paper: "Letter" });await writeFile("page.pdf", pdf);pdf = bx.pdf("https://example.com", paper="Letter")with open("page.pdf", "wb") as f: f.write(pdf)# The CLI prints on A4: it has no paper option.boxline pdf https://example.com -o page.pdf| Field | Default | Description |
|---|---|---|
url | required | The page. |
paper | "A4" | "A4", "A3", "A5", "Letter", "Legal" or "Tabloid". |
landscape | false | Landscape instead of portrait. |
printBackground | true | Print background colours and images. |
scale | 1 | Zoom of the printed page, from 0.1 to 2. |
It also takes the options every web API shares:
| Field | Default | Description |
|---|---|---|
waitUntil | "load" | When the page counts as loaded: "load", "domcontentloaded", "networkidle" (no network traffic for a moment) or "commit". |
delayMs | 0 | Extra wait after the page loads, up to 10,000 ms. Useful for pages that draw late. |
timeoutMs | 30000 | How long to wait for the page, from 1,000 to 120,000 ms. |
proxy | none | Load the page through a residential, datacenter or your own proxy, e.g. { "type": "residential", "country": "FR" }. The IP changes with every request unless you ask for "ip": "sticky". See Proxies. |
browser | standard | The page’s clock and language, e.g. { "mode": "realistic" } to follow the proxy’s country, or { "locale": "fr-FR", "timezone": "Europe/Paris" }. See Browser mode. |
blockAds | false | Refuse requests to ad and tracker sites while the page loads: faster, with less clutter, and no proxy data spent on them. See Ad and cookie-banner blocking. |
Response
The body is the PDF (application/pdf). It has the same headers as a screenshot: x-final-url, x-page-status, x-page-title, x-page-captcha and x-render-ms. See Screenshot.
Errors
| Status and code | What it means |
|---|---|
502 page_unreachable | The page could not be loaded. The message names the host and Chrome’s reason, e.g. could not load example.com: ERR_NAME_NOT_RESOLVED. When Chrome’s reason is a generic one, the message adds the real one in words, e.g. (the name does not resolve (DNS)). See why a page did not load. |
504 page_timeout | The page did not finish loading within timeoutMs. Try a longer time or another waitUntil. |
402 feature_not_in_plan | Your plan does not include this API, or the kind of proxy you asked for. |
429 rate_limited | Too many requests. Wait for the seconds in Retry-After. See Rate limits. |
Every field is in the API reference: Make a PDF.
These docs describe a beta API. Endpoints, fields and SDK methods may change before general availability; breaking changes will be listed in the changelog.