html2pdf

raw JSON →
0.0.11 verified Sat Apr 25 auth: no javascript deprecated

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.

error Error: spawn wkhtmltopdf ENOENT
cause wkhtmltopdf binary not installed or not in PATH.
fix
Install wkhtmltopdf: sudo apt-get install wkhtmltopdf (Linux) or download from https://wkhtmltopdf.org/downloads.html
error Error: write EPIPE
cause wkhtmltopdf process exited prematurely; often due to invalid HTML or missing assets.
fix
Ensure HTML is well-formed and all referenced resources (CSS, images) are available or use base64 encoding.
error TypeError: html2pdf is not a function
cause CommonJS require not used; trying to import as ES module.
fix
Use const html2pdf = require('html2pdf'); instead of import.
error Error: Module 'wkhtmltopdf' not found
cause Missing dependency or wrong import path.
fix
Install wkhtmltopdf package: npm install wkhtmltopdf. Alternatively, the html2pdf package bundles wkhtmltopdf as a dependency, but it may not be installed correctly.
deprecated Package is unmaintained since 2012 and wkhtmltopdf itself is in maintenance mode. Use puppeteer or other modern libraries.
fix 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'});
breaking Requires wkhtmltopdf binary to be installed on the system; not a pure Node.js solution.
fix Install wkhtmltopdf via system package manager (e.g., sudo apt-get install wkhtmltopdf) or download from https://wkhtmltopdf.org/downloads.html
gotcha No JavaScript rendering; complex CSS and JS-loaded content may not render correctly.
fix Use a headless browser like puppeteer for JavaScript-heavy content.
gotcha wkhtmltopdf 0.12.6 deprecated and may be removed from distributions; in some Linux distros the package is being dropped.
fix Switch to alternative PDF generation libraries (e.g., puppeteer, gotenberg, or weasyprint).
npm install html2pdf
yarn add html2pdf
pnpm add html2pdf

Shows basic usage: converting an HTML string to PDF and piping to a file. Requires wkhtmltopdf binary installed.

const wkhtmltopdf = require('wkhtmltopdf');
const fs = require('fs');
// OR directly using html2pdf wrapper:
const html2pdf = require('html2pdf');

// Convert HTML string to PDF
const html = '<html><body><h1>Hello World</h1></body></html>';
html2pdf(html, { options: { pageSize: 'A4' } }).pipe(fs.createWriteStream('output.pdf'));
console.log('PDF generated');
// Ensure wkhtmltopdf binary is installed and in PATH.