Generating PDFs


HeadlessTesting makes it very easy to generate PDFs from real Chromium-based browsers.


We provide access to real browsers, which means your PDFs are exactly like they should be.
Compared to other PDF creators like wkhtmltopdf, we use a real browser instance.


Our system is similar to pdfmake, except that this will not run on your own machine, but on our grid.
Take advantage of cloud scaling: generate hundreds of PDFs on our cloud architecture.

Generating your first PDF

Below is an example for both Puppeteer and Playwright.


const fs = require('fs')
const fsPromises = fs.promises
const puppeteer = require('puppeteer')

const browser = await puppeteer.connect({
    browserWSEndpoint: 'wss://chrome.headlesstesting.com?token=[YOUR-TOKEN]'
})

const page = await browser.newPage()
await page.goto('https://headlesstesting.com')
const pdf = await page.pdf({ format: 'A4' })
await fsPromises.writeFile('test.pdf', pdf)
browser.close()
const pw = require('playwright')
const fs = require('fs')
const fsPromises = fs.promises

(async () => {
  const browser = await pw.chromium.connect({
    wsEndpoint: 'wss://chrome.headlesstesting.com?token=[YOUR-TOKEN]&browserVersion=dev',
  })
  const context = await browser.newContext()
  const page = await context.newPage()

  await page.goto('https://headlesstesting.com/')
  const pdf = await page.pdf({ format: 'A4' })
  await fsPromises.writeFile('test.pdf', pdf)

  await browser.close()
})()

This example will save a test.pdf file with the contents of our homepage.

For more information and options regarding this topic, please see our Puppeteer PDF documentation and Playwright PDF documentation.