%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/opti/optisoftcom/.cache/yarn/v4/.tmp/cfc0dcc16ee8429e8392cdd73ce070e5/
Upload File :
Create Path :
Current File : /home/opti/optisoftcom/.cache/yarn/v4/.tmp/cfc0dcc16ee8429e8392cdd73ce070e5/README.md

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

#### Installation

```
npm install dynamic-html-pdf --save

```
#### Create template.html

```
<html>
    <head>
        Dynamic HTML to PDF
    </head>
    <body>
        <h1>Hi {{users[0].name}}</h1>
        <div>
            template
        </div>
    </body>
</html>

```
#### Feel free to use handlebar syntax: [Handlebar builtin helpers](http://handlebarsjs.com/builtin_helpers.html)

For example:
```
<ul>
  {{#each users}}
    <li>Name: {{this.name}}</li>
    <li>Age: {{this.age}}</li>
    <li>DOB: {{this.dob}}</li>
  {{/each}}
</ul>
```

#### 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 => {
        console.log(res)
    })
    .catch(error => {
        console.error(error)
    });
```

[For detailed Tutorial follow this link](http://www.thenextfact.com/convert-html-pdf-node-js-express-js-using-dynamic-html-pdf-3-steps/)

Zerion Mini Shell 1.0