I know this question is old, but these days I'd try puppeteer

const puppeteer = require("puppeteer");

async function printPDF() {
  const browser = await puppeteer.launch({ headless: true });
  const page = await browser.newPage();
  await page.goto("http:///stackoverflow.com", {
    waitUntil: "networkidle0",
  });
  const pdf = await page.pdf({
    width: 1200,
    height: 1920,
    pageRanges: "1-2",
    path: "so.pdf",
  });

  await browser.close();
  return pdf;
}
printPDF();

Also see HTML to PDF with Node.js

Answer from Piotr Cierpich on Stack Overflow
🌐
npm
npmjs.com › package › html2canvas
html2canvas - npm
January 22, 2022 - Screenshots with JavaScript. Latest version: 1.4.1, last published: 4 years ago. Start using html2canvas in your project by running `npm i html2canvas`. There are 3164 other projects in the npm registry using html2canvas.
      » npm install html2canvas
    
Published   Jan 22, 2022
Version   1.4.1
Author   Niklas von Hertzen
🌐
npm
npmjs.com › package › html2canvas-pro
html2canvas-pro - npm
November 6, 2025 - Screenshots with JavaScript. Next generation!. Latest version: 1.5.13, last published: a month ago. Start using html2canvas-pro in your project by running `npm i html2canvas-pro`. There are 77 other projects in the npm registry using html2canvas-pro.
      » npm install html2canvas-pro
    
Published   Nov 06, 2025
Version   1.5.13
Author   yorickshan
Discussions

html - A similar solution to html2canvas with nodejs - Stack Overflow
I'm using css, jquery and nodejs (with ejs and express) to create a website and I need to export a div with some text and some divs with a background-image as an image (jpg or png) but the best wou... More on stackoverflow.com
🌐 stackoverflow.com
How to use NPM package as normal javascript in HTML - Stack Overflow
I want to use html2canvas JS library in my application. I were able to use older versions of html2canvas in my application by directly loading html2canvas.js file in my HTML file. But newer versions are supported only through npm packages. More on stackoverflow.com
🌐 stackoverflow.com
How to get started with html2canvas
Okay, so this might seem like a simple question... But I'm new to part of stuff. On http://html2canvas.hertzen.com/getting-started it shows a very small tutorial... When I run npm install -g html2c... More on stackoverflow.com
🌐 stackoverflow.com
Is there an "html-2-canvas" that works with modern Angular? (Need to capture and save DOM as an image.)
https://github.com/frinyvonnick/node-html-to-image It use Puppeteer under the hood, you need to adapt your dockerfile to not use the user as root to avoid security issues. More on reddit.com
🌐 r/Angular2
3
1
September 6, 2024
🌐
html2canvas
html2canvas.hertzen.com › getting-started
Getting Started | html2canvas
You can install html2canvas through npm or download a built release.
🌐
npm
npmjs.com › search
html2canvas - npm search
A combine usage with jsPDF and html2canvas, which translating html content to PDF file. npm · jsPDF · html2canvas · html2canvas-pro · johnnywang• 1.6.0 • 12 hours ago • 7 dependents • ISCpublished version 1.6.0, 12 hours ago7 dependents licensed under $ISC ·
🌐
Hertzen
html2canvas.hertzen.com
html2canvas - Screenshots with JavaScript
html2canvas(document.querySelector("#capture")).then(canvas => { document.body.appendChild(canvas) }); Try it outDocumentation · npm install --save html2canvas · yarn add html2canvas · html2canvas.jshtml2canvas.min.js · 45kb gzipped · Follow @niklasvh ·
🌐
npm
npmjs.com › package › @codewonders › html2canvas
codewonders/html2canvas
Easy package.json exports.. Latest version: 1.0.1, last published: 14 years ago. Start using package in your project by running `npm i package`. There are 278 other projects in the npm registry using package.
🌐
html2canvas
html2canvas.net
HTML2Canvas: Capture Web Screenshots with JavaScript
You can install html2canvas via npm with the command npm install html2canvas.
Find elsewhere
🌐
npm
npmjs.com › package › @xuannghia › html2canvas
@xuannghia/html2canvas - npm
Screenshots with JavaScript. Latest version: 1.4.2, last published: 2 years ago. Start using @xuannghia/html2canvas in your project by running `npm i @xuannghia/html2canvas`. There are no other projects in the npm registry using @xuannghia/html2canvas.
      » npm install @xuannghia/html2canvas
    
Published   Jan 17, 2024
Version   1.4.2
Author   Niklas von Hertzen
🌐
npm
npmjs.com › package › @types › html2canvas
@types/html2canvas - npm
July 6, 2021 - Stub TypeScript definitions entry for html2canvas, which provides its own types definitions. Latest version: 1.0.0, last published: 4 years ago. Start using @types/html2canvas in your project by running `npm i @types/html2canvas`. There are 41 other projects in the npm registry using @types/html2canvas.
      » npm install @types/html2canvas
    
Published   Jul 06, 2021
Version   1.0.0
🌐
jsDelivr
jsdelivr.com › package › npm › html2canvas-fixes
html2canvas-fixes CDN by jsDelivr - A CDN for npm and GitHub
July 17, 2017 - A free, fast, and reliable CDN for html2canvas-fixes. Screenshots with JavaScript
Published   Jul 14, 2017
🌐
npm
npmjs.com › package › html2canvas-proxy
html2canvas-proxy - npm
July 6, 2018 - Cross-origin content proxy for html2canvas. Latest version: 1.0.1, last published: 7 years ago. Start using html2canvas-proxy in your project by running `npm i html2canvas-proxy`. There are 3 other projects in the npm registry using html2canvas-proxy.
      » npm install html2canvas-proxy
    
Published   Jul 06, 2018
Version   1.0.1
Author   Niklas von Hertzen
🌐
Don't Panic Labs
dontpaniclabs.com › blog › post › 2023 › 08 › 31 › using-html2canvas
Using html2canvas
August 31, 2023 - JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
npm
npmjs.com › package › jspdf-html2canvas
jspdf-html2canvas - npm
February 27, 2024 - A combine usage with jsPDF and html2canvas, which translating html content to PDF file.. Latest version: 1.5.2, last published: 2 years ago. Start using jspdf-html2canvas in your project by running `npm i jspdf-html2canvas`. There are 7 other projects in the npm registry using jspdf-html2canvas.
      » npm install jspdf-html2canvas
    
Published   Feb 27, 2024
Version   1.5.2
Author   johnnywang
🌐
jsDelivr
cdn.jsdelivr.net › dist
html2canvas-pro CDN by jsDelivr - A free, fast, and reliable Open Source CDN
Looking for a nice landing page for your package? https://www.jsdelivr.com/package/npm/html2canvas-pro
🌐
npm
npmjs.com › package › vue-html2canvas
vue-html2canvas - npm
Vue mixin for Html2Canvas. Latest version: 0.0.4, last published: 7 years ago. Start using vue-html2canvas in your project by running `npm i vue-html2canvas`. There are 5 other projects in the npm registry using vue-html2canvas.
      » npm install vue-html2canvas
    
Published   Sep 29, 2018
Version   0.0.4
Author   Jofferson Ramirez Tiquez
🌐
Stack Overflow
stackoverflow.com › questions › 50293693 › how-to-get-started-with-html2canvas
How to get started with html2canvas
Okay, so this might seem like a simple question... But I'm new to part of stuff. On http://html2canvas.hertzen.com/getting-started it shows a very small tutorial... When I run npm install -g html2c...
🌐
LogRocket
blog.logrocket.com › home › export react components as images using html2canvas
Export React components as images using html2canvas - LogRocket Blog
June 4, 2024 - html2canvas is a robust, easy to use solution for exporting React components as images. It does have some limitations, so be sure to read the documentation and test all possible scenarios to ensure you’re able to generate the desired view.