$ show eKoopmans/html2pdf.js
html2pdf.js is a client-side JavaScript library that converts HTML elements or strings into PDF documents entirely in the browser. It works by rendering the HTML to a canvas using html2canvas, then embedding that canvas image into a PDF generated with jsPDF. The library provides a Promise-based Worker API that allows chaining steps (from, toContainer, toCanvas, toPdf, save) and supports configuration of margins, page size, image quality, page breaks, and hyperlinks. It includes plugins for automatic page-break handling (CSS-based, legacy class-based, or avoid-all mode) and hyperlink extraction from anchor tags. The codebase is well-structured with a modular design, including a sophisticated DOM cloning utility (snapdom) that handles shadow DOM, canvas elements, iframes, and form controls. The project is actively maintained with CI/CD, semantic versioning, and visual diff testing.
The LLM identified 2 files worth highlighting for reuse:
A self-contained deep cloning utility for DOM elements that handles shadow DOM, canvas-to-image conversion, iframe fallback, image srcset freezing, textarea/input/select state preservation, and scroll position compensation. It is isolated from the rest of the project (no internal imports) and can be extracted for use in any project requiring robust DOM cloning with minimal modification.
Adds a static `getPageSize` method to jsPDF that computes page dimensions from orientation, unit, and format (including standard sizes like A4, Letter, etc.). It handles unit conversion (pt, mm, cm, in, px, pc, em, ex) and orientation swapping. This is a self-contained extension to jsPDF that could be reused independently in any project needing page size calculations.