Table of content

Website as PDF in Puppeteer

You can capture the total website page as pdf using Puppeteer's pdf() function. You can only convert the website to pdf when you are running in headless mode.

You will get the below error if you set {headless: false}
UnhandledPromiseRejectionWarning: Error: Protocol error (Page.printToPDF): PrintToPDF is not implemented
const puppeteer = require('puppeteer');
async function run(){
    const browser = await puppeteer.launch()
    const page = await browser.newPage();
    await page.goto('');
    await page.pdf({path: 'website_as_pdf.pdf', format: 'A4'});
    await browser.close();


You can have the pdf in different sizes, In the above example, I am using with A4 size.

About Author :

I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions