snapdom html2pdf plugin

April 14, 2026 ยท View on GitHub

A SnapDOM plugin that renders a webpage as a pdf with selectable text and links via html2pdf.js

Install

npm i snapdom-html2pdf-plugin
import { snapdom } from '@zumer/snapdom'
import { html2pdfSnap } from 'snapdom-html2pdf-plugin'
snapdom.plugins([html2pdfSnap, { opts }])

const capture = document.getElementById("capture")
await result.toHtml2pdfSnap({ element: capture, html2pdfSnap })

Options

html2pdf docs

NameTypeDefaultDescription
marginnumber or array0PDF margin (in jsPDF units). Can be a single number, [vMargin, hMargin], or [top, left, bottom, right].
filenamestring'file.pdf'The default filename of the exported PDF.
pagebreakobject{mode: ['css', 'legacy']}Controls the pagebreak behaviour on the page. See Page-breaks below.
imageobject{type: 'jpeg', quality: 0.95}The image type and quality used to generate the PDF. See Image type and quality below.
enableLinksbooleantrueIf enabled, PDF hyperlinks are automatically added ontop of all anchor tags.
html2canvasobject{ }Configuration options sent directly to html2canvas (see here for usage).
jsPDFobject{ }Configuration options sent directly to jsPDF (see here for usage).

License

MIT