Table of content

Website as PDF

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 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.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions