title: Html to pdf with puppeteer
body: <p>I'm new to nodejs, express and puppeteer as well. The task is to create webserver that convert html to pdf. After research I found puppeteer and phantomsjs for that purpose (but phantomjs is not supportable anymore).
  I created simple webserver that takes json with html and other settings. But phantomjs is more faster than puppeteer, maybe I have some mistakes?</p>
  
  <p>Puppeteer code:<br>
  Route:</p>
  
  <pre><code>router.post("/raw", jsonParser, async function(request, response) {
          html2PdfConverter(request.body.html, pdf =&gt; {
          response.setHeader('Content-Type', 'application/pdf');
          response.send(pdf);
        }, 
          request.body.options,
          request.body.puppeteerArgs, 
          request.body.remoteContent).catch(err =&gt; {
          console.log(err);
          response.status(500).send('An error occurred');
        });
      });
  </code></pre>
  
  <p>Html2PdfConverter</p>
  
  <pre><code>const puppeteer = require('puppeteer');
  
  let convertHTMLToPDF = async (html, callback, options = null, puppeteerArgs=null, remoteContent=true) =&gt; {
      if (typeof html !== 'string') {
          throw new Error(
              'Invalid Argument: HTML expected as type of string and received a value of a different type. Check your request body and request headers.'
          );
      }
      let browser;
      if (puppeteerArgs) {
          browser = await puppeteer.launch(puppeteerArgs);
      } else {
          browser = await puppeteer.launch();
      }
  
      const page = await browser.newPage();
      if (!options) {
          options = { format: 'Letter' };
      }
  
      if (remoteContent === true) {
          await page.goto(`data:text/html,${html}`, {
              waitUntil: 'networkidle0'
          });
      } else {
          await page.setContent(html);
      }
  
      await page.pdf(options).then(callback, function(error) {
          console.log(error);
      });
      await browser.close();
  };
  
  module.exports = convertHTMLToPDF;
  </code></pre>
  
  <p>I think that phantomjs works faster because pdf method returns stream and html and pdf files creates in Temp folder.</p>
  
  <p>I would be grateful for any help.</p>