Skip to content Skip to sidebar Skip to footer

Polymer Starter Kit With Node, Express, And Puppeteer

Okay, I'm a newbie to all this so any help greatly appreciated. I've managed to use Node and Express to serve up Polymer Starter Kit (PSK) website from the Polymer build directory

Solution 1:

Are you invoking functionPDFCreate in a browser context? It's not going to work even with browserify or webpack as @YouneL suggested.

You should expose endpoint in express app serving your PDF:

app.get('/hn', function(req, res) {
    functionPDFCreate().then(() => {
        // now file is written on the disk
        res.sendFile('hn.pdf', { root: '.' });
    });
});

functionPDFCreate should look like this:

const puppeteer = require('puppeteer');

async function functionPDFCreate() {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto('https://news.ycombinator.com', { waitUntil: 'networkidle2' });
    await page.pdf({ path: 'hn.pdf', format: 'A4' });

    await browser.close();
}

In your browser app, you should have download button like this (framework agnostic example):

<ahref="http://localhost:3000/hn"download="hn.pdf">Download HN PDF</a>

Post a Comment for "Polymer Starter Kit With Node, Express, And Puppeteer"