html2pdf.js is a JavaScript library designed for client-side conversion of HTML elements or entire webpages into printable PDF documents. It leverages `html2canvas` for rendering HTML to a canvas and `jsPDF` for generating the PDF output. The current stable version is 0.14.0, released in January 2026. This library is strictly browser-based and does not run in Node.js environments. It offers a promise-based API for advanced workflow customization, allowing developers to chain operations and insert custom functions between steps of the conversion process. Key differentiators include its entirely client-side operation, eliminating server-side rendering, and its modular, configurable workflow that provides fine-grained control over the PDF generation process, including page-break handling, image quality, and progress tracking.
npm install html2pdf.jsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import `html2pdf.js` as an ES module, create an HTML element dynamically, and then use the `html2pdf` function with common options to generate and save a PDF document from that element.
Ensure the library is only executed within a web browser context. For server-side PDF generation, consider headless browser solutions (e.g., Puppeteer) or dedicated Node.js PDF libraries.
Review the jspdf 4.0.0 release notes for any breaking changes if you are using advanced html2pdf.js configurations that rely on jspdf internals. Test your application thoroughly after upgrading to html2pdf.js v0.13.0 or later.
For simplicity, always use `html2pdf.bundle.min.js` unless you have a specific need to manage `html2canvas` and `jsPDF` versions independently. If using the unbundled version, ensure `html2canvas` and `jsPDF` are loaded *before* `html2pdf.min.js`.
Simplify complex layouts and CSS when possible for PDF conversion. Test different `html2canvas` options like `scale`, `dpi`, and `letterRendering` to find the best balance. Consider pre-rendering complex elements as images if precise fidelity is critical.
Ensure the code is running in a browser. If using npm, verify your bundler (e.g., Webpack, Rollup) correctly includes `html2pdf.js`. If using CDN, confirm the script tag is present and loaded before `html2pdf` is called.
Import the default export first, then access `Worker` as a property: `import html2pdf from 'html2pdf.js'; const worker = new html2pdf.Worker();`.
Adjust `html2canvas` options (e.g., `scale`, `useCORS`, `logging`). Ensure images are loaded and fonts are available. For complex layouts, try simplifying the HTML/CSS structure specifically for the PDF conversion target, or delay conversion until all dynamic content has settled.