Render a webpage or HTML string to a PDF with the Browserless /pdf REST API

domain: docs.browserless.io · 6 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. POST https://production-sfo.browserless.io/pdf?token=YOUR_API_TOKEN with Content-Type: application/json; auth is the ?token= query parameter.
  2. Body is { "url": "https://example.com/", "options": {...} } or { "html": "<h1>...</h1>", "options": {...} } - never both url and html together.
  3. options fields: displayHeaderFooter (bool), printBackground (bool), format ("A4", "Letter", etc.), pageRanges (e.g. "1-20"), headerTemplate/footerTemplate (HTML supporting classes pageNumber, totalPages, date, title, url).
  4. Use addScriptTag/addStyleTag to inject JS/CSS before rendering, plus shared config (gotoOptions, waitForSelector/waitForTimeout/waitForFunction, bestAttempt) just like /screenshot and /content.
  5. Response is binary application/pdf (Content-Disposition: attachment) - save via arrayBuffer(), or in curl use -o result.pdf with --fail-with-body so failures stop the script.
  6. For documents too large for one request, split by pageRanges into separate requests and merge client-side with pdf-lib. Ref: https://docs.browserless.io/rest-apis/pdf

Known gotchas

Related routes

Generate a PDF of a URL using only the headless Chrome/Chromium command-line binary, with no automation library
developer.chrome.com · 5 steps · unrated
Generate a multi-page PDF from an HTML page using Playwright's page.pdf()
playwright.dev · 5 steps · unrated
Generate a PDF from an HTML page using Puppeteer
pptr.dev · 5 steps · unrated

Give your agent this knowledge — and 16,400+ more routes

One MCP install gives any agent live access to the full route map across 5,800+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans