html2pdf.js renders web pages or DOM elements to downloadable PDFs entirely in the browser. It combines html2canvas and jsPDF and does not run in Node.js.
Overview
html2pdf.js is a browser-side library that converts a webpage or a chosen DOM element into a PDF without a server round trip. Rendering goes through html2canvas to capture layout as an image, then jsPDF builds the PDF file and can prompt the user to save it.
You can load it from a CDN, download a bundled script, or install via npm or Bower. The source states that npm may be used to manage a front-end project, but execution must happen in a browser, not in Node.js. A promise-based Worker API lets you chain steps such as setting the source, tuning options, and saving with a chosen filename.
Configuration covers margins, default filename, image type and quality, optional PDF links over anchor tags, and page-break behavior using CSS, legacy class markers, or rules that avoid splitting elements across pages. Dependencies html2canvas and jsPDF load automatically with npm or the bundled build; unbundled builds require including those scripts in the correct order.
Known limitations described in the source include rasterized rather than selectable text, reliance on html2canvas accuracy, and canvas size limits on very large pages.
Key features
- In-browser PDF generation
- Promise-based Worker API
- Configurable margins and filename
- CSS and legacy page breaks
- JPEG or PNG image quality options
- Optional PDF hyperlink overlay
- CDN, npm, or bundled install
Use cases
- Export a page region to PDF
- Client-only printable invoices or reports
- Screenshots to PDF from the console