pdf-creator-node is a Node.js library that renders PDF documents from HTML and Handlebars templates using Puppeteer's headless Chromium. It is an open-source (MIT-licensed) package that accepts an HTML string, a data object, and print options, then produces a PDF file, buffer, or stream.
What is pdf-creator-node?
pdf-creator-node is an npm package that converts HTML + Handlebars templates into PDF files, buffers, or streams. It runs on Node.js 18 or newer and, as of v4, uses Puppeteer to drive headless Chromium instead of the deprecated PhantomJS / html-pdf. The package exports a create function that takes a document object (with html, data, and either path or type) and an options object (with format, orientation, border, header, footer, pdfChrome, base, and handlebarsHelpers).
Key Features
- Chromium rendering — v4 renders with headless Chromium, supporting modern CSS like flexbox, grid, and web fonts, unlike older PhantomJS versions.
- Handlebars templating — Built-in Handlebars engine with an
ifCondhelper for conditional comparisons (operators:==,===,!=,!==,<,<=,>,>=,&&,||), and support for custom helpers via thehandlebarsHelpersoption. - Flexible output — Output a PDF file (default with
path), a Node.js Buffer, or a Stream by settingtypeto"file","buffer", or"stream". - Page layout controls — Options for paper size (A3, A4, A5, Legal, Letter, Tabloid or custom width/height), orientation (portrait/landscape), and borders as margins.
- Repeating headers and footers — Configure via the
pdfChromeobject or directheader/footeroptions; supports raw HTML, centered titles, copyright text, and automatic page numbers using{{page}}/{{pages}}placeholders. - Custom fonts and images — Use remote URLs, local files with a
baseoption, base64 data URLs, and WebP images; fonts can be loaded via@font-faceor<link>tags in the HTML head. - PDF via Puppeteer print pipeline — Mapping to Chromium's print path; navigation tokens like
{{page}}are converted automatically.
Who is it for?
- Node.js developers who need to generate invoices, reports, or letters from HTML templates without writing PDF vector drawing code.
- Serverless architects evaluating whether to run PDF generation on AWS Lambda; this package can work but requires container images or a trimmed Chromium binary due to Lambda's 250 MB unzipped deployment limit.
- CI/CD pipeline maintainers who want to automate PDF generation from HTML snippets in testing or release workflows.
What can you do with it?
- Generate invoices — Feed an HTML invoice template with Handlebars loops to render line items, totals, and customer details into a formatted PDF.
- Create reports — Compose HTML reports with tables, charts (via images), and headers/footers, then export to A4/Letter PDFs with custom margins.
- Build a document generation microservice — Wrap the library in an Express/Fastify endpoint that accepts JSON and an HTML template and returns PDF buffers to clients.
How does it work?
The create function takes a document object (HTML string, data object, and output path/type) plus options. It compiles the Handlebars template with the provided data, launches headless Chromium via Puppeteer, loads the HTML with base as the base URL if provided, and uses Chromium's print-to-PDF feature to render the output. The returned Promise resolves with the result object when the PDF is written.
Alternatives
- PDFKit — a pure JavaScript PDF generation library that offers a drawing API for precise vector control without HTML.
- pdf-lib — a JavaScript library for creating and editing PDFs programmatically, useful for modifying existing documents.
- html-pdf — a legacy package using PhantomJS that pdf-creator-node v4 no longer depends on; it is deprecated.
FAQ
Does pdf-creator-node support page numbers in footers?
Yes, you can include {{page}} and {{pages}} in the footer HTML. When using pdfChrome.footer, page numbers are enabled by default if copyright is set; for page numbers only, set showPageNumbers: true and omit copyright.
Can I output a buffer instead of a file?
Yes, set type to "buffer" in the document object and omit path. You can also get a Stream with type: "stream", or write to a file by setting path (the default).
Does it work with custom fonts?
Yes, because v4 uses Chromium rendering. You can load hosted fonts via <link> in the HTML, or local fonts with @font-face and a relative URL plus the base option pointing to your assets folder. For header/footer HTML, repeat the font link because it doesn't inherit the main template's styles.
Is there a way to run it on AWS Lambda?
It can run, but the default puppeteer install bundles a full Chromium build that often exceeds Lambda's 250 MB unzipped size limit for zip deployments. Common workarounds include using Lambda container images, trimming Chromium with community layers like @sparticuz/chromium plus puppeteer-core, or running PDF generation on ECS/Fargate/EC2 instead.
What are the Node.js version requirements?
pdf-creator-node v4 requires Node.js 18 or newer.








