title: Use Puppeteer to Generate a PDF on Client Side
body: <p>I'm struggling to get Puppeteer to download a file within the browser. I currently have it saving the file locally on Cloud9, but I want to click a download PDF button and have it download in Chrome.</p>
  
  <p>I've tried saving the page.pdf to a variable and that hasn't worked. I've also tried opening the locally saved file, but I can't get that to work either. </p>
  
  <pre><code>var express = require("express");
  var puppeteer = require("puppeteer");
  
  module.exports = function pdf(url, req) {(async () =&gt; {
        var browser = await puppeteer.launch();
        var page = await browser.newPage();
        await page.goto('https://node-and-mysql-mbegg.c9users.io/clients/'+req.params.id+'/reports/monthlyreport/'+req.params.marketplace+'/'+req.params.month, {waitUntil: 'networkidle2'});
        await page.pdf({path: 'public/temp/Performance Report -'+req.params.month+'.pdf', format: 'A4', landscape: true, printBackground: true});
  
        await browser.close();
      })();
  }
  
  ///Print PDF route
  router.get("/clients/:id/reports/monthlyreport/:marketplace/:month/pdf", function(req, res) {
      var url = "/clients/"+req.params.id+"/reports/monthlyreport/"+req.params.marketplace+"/"+req.params.month
      pdf(url, req);
      res.contentType("application/pdf");
      res.send(pdf);;
  });
  </code></pre>
  
  <p>I know that the res.send(pdf) requires the page.pdf() to be saved to a variable and returned. I just didn't remove that from the route.</p>
  
  <p>What happens when I save page.pdf() to a variable is I just get a blank file - not PDF - and it appears just to be a blank buffer or something. I don't know what I'm doing wrong to not get the file downloading in the chrome browser.</p>