Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Generate PDFs from HTML and Handlebars templates in Node.js using Puppeteer.
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.
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).
ifCond helper for conditional comparisons (operators: ==, ===, !=, !==, <, <=, >, >=, &&, ||), and support for custom helpers via the handlebarsHelpers option.path), a Node.js Buffer, or a Stream by setting type to "file", "buffer", or "stream".pdfChrome object or direct header/footer options; supports raw HTML, centered titles, copyright text, and automatic page numbers using {{page}} / {{pages}} placeholders.base option, base64 data URLs, and WebP images; fonts can be loaded via @font-face or <link> tags in the HTML head.{{page}} are converted automatically.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.
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.
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).
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.
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.
pdf-creator-node v4 requires Node.js 18 or newer.
