node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org ยป


How to Setup: Dynamic handlebars html pdf to create dynamic content html to pdf.


npm install dynamic-html-pdf --save

Create template.html

        Dynamic HTML to PDF
        <h1>Hi {{users[0].name}}</h1>

Feel free to use handlebar syntax: Handlebar builtin helpers

For example:

  {{#each users}}
    <li>Name: {{}}</li>
    <li>Age: {{this.age}}</li>
    <li>DOB: {{this.dob}}</li>

How to use Dynamic HTML to PDF

var fs = require('fs');
var pdf = require('dynamic-html-pdf');
var html = fs.readFileSync('template.html', 'utf8');

var options = {
    format: "A3",
    orientation: "portrait",
    border: "10mm"

var users = [
        name: 'aaa',
        age: 24,
        dob: '1/1/1991'
        name: 'bbb',
        age: 25,
        dob: '1/1/1995'
        name: 'ccc',
        age: 24,
        dob: '1/1/1994'

var document = {
    type: 'buffer',     // 'file' or 'buffer'
    template: html,
    context: {
        users: users
    path: "./output.pdf"    // it is not required if type is buffer

pdf.create(document, options)
    .then(res => {
    .catch(error => {

For detailed Tutorial follow this link