A Node.js wrapper for wkhtmltopdf that converts HTML to PDF. Current version 0.0.11 is unmaintained since 2012 and only works with the legacy wkhtmltopdf binary (0.12.x series). Requires wkhtmltopdf to be installed separately on the system. Compared to modern alternatives like puppeteer or pdfmake, it offers no JS rendering support and is essentially deprecated. No release cadence; last commit was years ago. Not recommended for new projects.
npm install html2pdfVerified import paths — ran on the pinned version, not inferred.
Shows basic usage: converting an HTML string to PDF and piping to a file. Requires wkhtmltopdf binary installed.
Migrate to puppeteer: npm install puppeteer. Then use: const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setContent(html); await page.pdf({path: 'output.pdf'});Install wkhtmltopdf via system package manager (e.g., sudo apt-get install wkhtmltopdf) or download from https://wkhtmltopdf.org/downloads.html
Use a headless browser like puppeteer for JavaScript-heavy content.
Switch to alternative PDF generation libraries (e.g., puppeteer, gotenberg, or weasyprint).
Install wkhtmltopdf: sudo apt-get install wkhtmltopdf (Linux) or download from https://wkhtmltopdf.org/downloads.html
Ensure HTML is well-formed and all referenced resources (CSS, images) are available or use base64 encoding.
Use const html2pdf = require('html2pdf'); instead of import.Install wkhtmltopdf package: npm install wkhtmltopdf. Alternatively, the html2pdf package bundles wkhtmltopdf as a dependency, but it may not be installed correctly.