Skip to main content

Generating PDFs

info

Currently, Browserless V2 is available in production via two domains: production-sfo.browserless.io and production-lon.browserless.io

The /pdf API allows for simple navigation to a site and capturing a PDF. Browserless will respond with a Content-Type of application/pdf and a Buffer of the PDF file. Similar to screenshots, this REST API also exposes puppeteer's pdf options via an options property in the JSON body for granular control.

You can check the full Open API schema here for all options and properties.

info

This route requires either a url or html property in the JSON body. When html is present Browserless will render the HTML for you and capture the PDF.

On this collection we’ll look at:

Basic Usage

Rest API (Without Stealth)

Bot detection

Browserless recommends using our REST API to generate PDFs, unless you need to get past bot detectors.

curl -X POST \
https://production-sfo.browserless.io/pdf?token=YOUR_API_TOKEN_HERE \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com/",
"options": {
"displayHeaderFooter": true,
"printBackground": false,
"format": "A0"
}
}'
warning

We do not allow setting a options.path

BQL (Stealth)

If the /pdf API is getting blocked by bot detectors, then we would recommend trying BrowserQL.

mutation PDF {
goto(url: "https://example.com") {
status
}

pdf(displayHeaderFooter: true, printBackground: false, format: a0) {
base64
}
}
BQL Schemas

For more details on BQL mutations, refer to the BrowserQL Schema reference pages.