{"id":18423,"library":"html2pdf","title":"html2pdf","description":"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.","status":"deprecated","version":"0.0.11","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install html2pdf","lang":"bash","label":"npm"},{"cmd":"yarn add html2pdf","lang":"bash","label":"yarn"},{"cmd":"pnpm add html2pdf","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"The package is a thin wrapper that spawns wkhtmltopdf binary; it will not work without it.","package":"wkhtmltopdf","optional":false}],"imports":[{"note":"ESM import fails because the package has no default export; only CJS require works.","wrong":"import html2pdf from 'html2pdf';","symbol":"default","correct":"const html2pdf = require('html2pdf');"},{"note":"No named export; the module exports a function directly.","wrong":"import { html2pdf } from 'html2pdf';","symbol":"html2pdf","correct":"const html2pdf = require('html2pdf');"},{"note":"No types exist; trying to import types will fail.","wrong":"import type Html2Pdf from 'html2pdf';","symbol":"type imports","correct":"not applicable (no TypeScript types)"}],"quickstart":{"code":"const wkhtmltopdf = require('wkhtmltopdf');\nconst fs = require('fs');\n// OR directly using html2pdf wrapper:\nconst html2pdf = require('html2pdf');\n\n// Convert HTML string to PDF\nconst html = '<html><body><h1>Hello World</h1></body></html>';\nhtml2pdf(html, { options: { pageSize: 'A4' } }).pipe(fs.createWriteStream('output.pdf'));\nconsole.log('PDF generated');\n// Ensure wkhtmltopdf binary is installed and in PATH.","lang":"javascript","description":"Shows basic usage: converting an HTML string to PDF and piping to a file. Requires wkhtmltopdf binary installed."},"warnings":[{"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'});","message":"Package is unmaintained since 2012 and wkhtmltopdf itself is in maintenance mode. Use puppeteer or other modern libraries.","severity":"deprecated","affected_versions":"all"},{"fix":"Install wkhtmltopdf via system package manager (e.g., sudo apt-get install wkhtmltopdf) or download from https://wkhtmltopdf.org/downloads.html","message":"Requires wkhtmltopdf binary to be installed on the system; not a pure Node.js solution.","severity":"breaking","affected_versions":"all"},{"fix":"Use a headless browser like puppeteer for JavaScript-heavy content.","message":"No JavaScript rendering; complex CSS and JS-loaded content may not render correctly.","severity":"gotcha","affected_versions":"all"},{"fix":"Switch to alternative PDF generation libraries (e.g., puppeteer, gotenberg, or weasyprint).","message":"wkhtmltopdf 0.12.6 deprecated and may be removed from distributions; in some Linux distros the package is being dropped.","severity":"gotcha","affected_versions":">=0.12.6"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install wkhtmltopdf: sudo apt-get install wkhtmltopdf (Linux) or download from https://wkhtmltopdf.org/downloads.html","cause":"wkhtmltopdf binary not installed or not in PATH.","error":"Error: spawn wkhtmltopdf ENOENT"},{"fix":"Ensure HTML is well-formed and all referenced resources (CSS, images) are available or use base64 encoding.","cause":"wkhtmltopdf process exited prematurely; often due to invalid HTML or missing assets.","error":"Error: write EPIPE"},{"fix":"Use const html2pdf = require('html2pdf'); instead of import.","cause":"CommonJS require not used; trying to import as ES module.","error":"TypeError: html2pdf is not a function"},{"fix":"Install wkhtmltopdf package: npm install wkhtmltopdf. Alternatively, the html2pdf package bundles wkhtmltopdf as a dependency, but it may not be installed correctly.","cause":"Missing dependency or wrong import path.","error":"Error: Module 'wkhtmltopdf' not found"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}