Registry / http-networking / pdf-creator-node

pdf-creator-node

JSON →
library4.0.1jsnpmunverified

pdf-creator-node is a Node.js library for converting HTML and Handlebars templates into PDF documents. It leverages Puppeteer, a headless Chromium browser, for rendering, ensuring support for modern CSS features like Flexbox, Grid, and web fonts. As of version 4.0.1, it has moved entirely to Puppeteer, replacing its prior reliance on PhantomJS/html-pdf. This change, introduced in v4.0.0, brings improved rendering fidelity and a more actively maintained underlying engine, though it comes with a larger install footprint due to Chromium. The library is actively maintained, as evidenced by recent v4.0.x releases, and provides a programmatic API to generate reports, invoices, and letters from templated HTML. It balances ease of use for HTML-centric document generation with the resource considerations inherent to a Chromium-based solution, suitable for small to medium-scale production workloads.

npm install pdf-creator-node
INSTALL
IMPORT
SIG · PDF-CREATOR-NODE
P
pdf-creator-node
http-networkingjavascriptv4.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pdf
import pdf from 'pdf-creator-node';
const pdf = require('pdf-creator-node');
While CommonJS `require` works, TypeScript users should prefer ESM `import` for better type inference and modern module practices. `pdf` is the default export.
PdfDocument
import type { PdfDocument } from 'pdf-creator-node';
Used for type-checking the document object structure. Important for TypeScript projects.
PdfCreateOptions
import type { PdfCreateOptions } from 'pdf-creator-node';
Used for type-checking the PDF creation options. Essential for robust TypeScript usage.

This quickstart demonstrates how to create a PDF from an HTML and Handlebars template, including dynamic data, custom headers, and footers, saving it to a file, using ESM syntax.

import pdf from "pdf-creator-node"; import fs from "fs"; import path from "path"; const htmlTemplate = ` <!DOCTYPE html> <html> <head> <style> body { font-family: sans-serif; margin: 20mm; } h1 { color: #333; } table { width: 100%; border-collapse: collapse; margin-top: 20px; } th, td { border: 1px solid #ddd; padding: 8px; text-align: left; } .footer { position: fixed; bottom: 0; width: 100%; text-align: center; font-size: 10px; color: #666; } </style> </head> <body> <h1>User Report</h1> <table> <thead> <tr> <th>Name</th> <th>Age</th> </tr> </thead> <tbody> {{#each users}} <tr> <td>{{this.name}}</td> <td>{{this.age}}</td> </tr> {{/each}} </tbody> </table> <div class="footer">Page {{page}} of {{pages}}</div> </body> </html> `; const usersData = [ { name: "Alice", age: 30 }, { name: "Bob", age: 24 }, { name: "Charlie", age: 35 } ]; const options = { format: "A4", orientation: "portrait", border: "10mm", header: { height: "15mm", contents: { default: '<h2 style="text-align: center;">PDF Report Header</h2>' } }, footer: { height: "10mm", contents: { default: '<span style="color: #444;">{{page}}</span>/<span>{{pages}}</span>' } }, path: path.join(process.cwd(), 'output.pdf') // Use path.join for cross-platform compatibility }; const document = { html: htmlTemplate, data: { users: usersData }, path: options.path, }; pdf.create(document, options) .then((res) => console.log('PDF created:', res.filename)) .catch((err) => console.error('Error creating PDF:', err));
Debug
Known issues
breakingVersion 4.0.0 replaced PhantomJS with Puppeteer (headless Chromium) for rendering. This results in a larger installation size (hundreds of MB for Chromium download) and potential differences in PDF layout and styling compared to previous versions. Deprecated options like `phantomPath` are now ignored.
fix
Review PDF output for layout changes. Account for increased install size, especially in CI/CD environments (consider `PUPPETEER_CACHE_DIR` or `PUPPETEER_SKIP_DOWNLOAD`). Remove PhantomJS-specific options from `PdfCreateOptions`.
affects: >=4.0.0
breakingThe `footer.contents` option for `PdfCreateOptions` has changed behavior in v4.0.0. Only one template (`default`, `first`, or `last`) is applied; per-page numeric keys (e.g., for page 2) are no longer supported.
fix
Consolidate footer content into a single `default`, `first`, or `last` template. Use `{{page}}` and `{{pages}}` placeholders within that single template for page numbering.
affects: >=4.0.0
gotchaPuppeteer, and by extension `pdf-creator-node` (v4+), downloads a Chromium browser instance upon installation. This can significantly increase `node_modules` size and installation time, particularly in resource-constrained environments or CI/CD pipelines.
fix
For CI/CD, consider setting `PUPPETEER_SKIP_DOWNLOAD=true` if Chromium is pre-installed or `PUPPETEER_CACHE_DIR` to cache the downloaded browser across builds. Be aware of the memory and CPU footprint when running many concurrent PDF generation tasks.
affects: >=4.0.0
gotchaThe minimum Node.js version required is 18. Using older Node.js versions will lead to compatibility issues and errors.
fix
Ensure your project's Node.js environment is version 18 or newer.
affects: <4.0.0
Errors
Common errors & fixes
Error: Cannot find module 'pdf-creator-node'
The package is not installed or incorrectly referenced.
fix
Run `npm install pdf-creator-node` or `yarn add pdf-creator-node`.
Error: Node.js 18 or newer is required.
Running the package with an unsupported Node.js version.
fix
Upgrade your Node.js environment to version 18 or higher.
Error: Failed to launch the browser process! The browser should be installed via 'npm install'
Puppeteer failed to find or launch Chromium, likely due to a failed download or permissions issue during installation, or `PUPPETEER_SKIP_DOWNLOAD` being set without a pre-installed browser.
fix
Ensure `puppeteer` can download Chromium by checking network access during `npm install`. If `PUPPETEER_SKIP_DOWNLOAD` is set, ensure Chromium is installed and `PUPPETEER_EXECUTABLE_PATH` points to it. Check file permissions for the `node_modules` directory.
TypeError: pdf.create is not a function
Incorrect import or require statement, or accessing an uninitialized module. Possibly trying to destructure `pdf` from a `require` call that returns the default export.
fix
For CommonJS, use `const pdf = require('pdf-creator-node');`. For ESM (TypeScript/modern Node.js), use `import pdf from 'pdf-creator-node';` and ensure your environment supports ESM.
Upgrade
Version history
4.0.1latest on npm
Audit
Dependencies
puppeteerrequiredCore rendering engine (headless Chromium) for PDF generation. Automatically installed.
Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
pdf-creator-node — npm install pdf-creator-node · libregistry