Search code examples
javascriptnode.jsnpmhummus.js

HummusJS - Convert HTML page to PDF in JavaScript


How can I use hummusJS to convert HTML code to PDF?
So far I am able to convert JPG images to pdf, as well as merge multiple pdfs.


Solution

  • puppeteer is a good solution:

    Installation

    npm i puppeteer
    # or "yarn add puppeteer"
    

    Example - create a PDF.

    const puppeteer = require('puppeteer');
    
    (async () => {
      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();
    })();