Skip to main content

PDFs

The pdf mutation 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.

On this collection we'll look at:

BQL Schemas

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

Rest API

Generating PDFs can also be done with Browserless Rest API. For endpoint details, parameters, and code samples, see the Browserless REST API.

Basic Usage

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

pdf(displayHeaderFooter: true, printBackground: false, format: a0) {
base64
}
}
Waiting for Elements

For more reliable PDF generation, it's important to wait for the site and elements to be ready before capturing. Learn more about BrowserQL's built-in wait methods in our Waiting for Things documentation.

Setting HTML Content

You can set the HTML content of the page to render dynamically generated content as well.

mutation PDF {
content(html: "<h1>Hello, World!</h1>") {
status
}

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

Next Steps

Ready to take your PDF generation to the next level? Explore these key areas: