Node.js · Handlebars · html-pdf

pdf-creator-node

Turn HTML templates into PDFs — write templates with Handlebars, get a file, buffer, or stream.

npm i pdf-creator-node

Node 18+ · See full readme on GitHub for TypeScript, validation, and handlebarsHelpers.

Quick start

Minimal example: load a template, pass data, call create.

var pdf = require("pdf-creator-node");
var fs = require("fs");

var html = fs.readFileSync("template.html", "utf8");

var options = {
  pdfChrome: {
    layout: { format: "A3", orientation: "portrait", border: "10mm" },
    header: { title: "My report" },
    footer: { copyright: "© 2026", showPageNumbers: true },
  },
};

var document = {
  html: html,
  data: { users: [ /* … */ ] },
  path: "./output.pdf",
  type: "", // "" = file | "buffer" | "stream"
};

pdf
  .create(document, options)
  .then((res) => console.log(res))
  .catch((err) => console.error(err));

Step-by-step

From install to your first PDF in six steps.

  1. Install
    npm i pdf-creator-node
  2. Load the package and read your template
    var pdf = require("pdf-creator-node");
    var fs = require("fs");
    var html = fs.readFileSync("template.html", "utf8");
  3. Author your HTML

    Use Handlebars (e.g. {{#each users}}).

    <!DOCTYPE html>
    <html>
      <head><meta charset="utf-8" /><title>Hello</title></head>
      <body>
        <h1>User list</h1>
        <ul>
          {{#each users}}
          <li>Name: {{this.name}}</li>
          <li>Age: {{this.age}}</li>
          {{/each}}
        </ul>
      </body>
    </html>
  4. Configure PDF options

    Size with height/width (e.g. 10.5in; units: mm, cm, in, px) or format (A3, A4, A5, Legal, Letter, Tabloid) and orientation.

    var options = {
      format: "A3",
      orientation: "portrait",
      border: "10mm",
      header: {
        height: "45mm",
        contents: '<div style="text-align: center;">Author: …</div>',
      },
      footer: {
        height: "28mm",
        contents: {
          first: "Cover page",
          2: "Second page",
          default: '<span>{{page}}/{{pages}}</span>',
          last: "Last page",
        },
      },
    };
  5. Build the document object

    Set type to "buffer" or "stream" to avoid writing a file.

  6. Call pdf.create

    pdf.create(document, options) returns a Promise.

Layout, header, footer, copyright

Use pdfChrome on the second argument for paper size, repeating header (title or html), and footer with optional copyright and page numbers ({{page}} / {{pages}}). Plain strings are HTML-escaped. Direct format / header / footer on the same object override pdfChrome.

var options = {
  pdfChrome: {
    layout: {
      format: "A4",
      orientation: "portrait",
      border: "12mm",
    },
    header: { title: "Quarterly report" },
    footer: {
      copyright: "© 2026 My Company",
      showPageNumbers: true,
    },
  },
};

pdf.create(document, options);

For full control, pass header, footer, and format in the same options object as html-pdf expects (see readme).

ifCond helper

Compare two values inside templates — two operands only.

Operators: ==, ===, !=, !==, <, <=, >, >=, &&, ||.

{{#ifCond inputData "===" toCheckValue}}
  …
{{/ifCond}}