-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (27 loc) · 901 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require('dotenv/config')
const pdf = require('handlebars-pdf');
const fs = require('fs');
const path = require("path");
/////////////////////////////////////// ALTER FILENAME HERE //////////////////////////////////////////////////////
const fileName = 'example.hbs';
const templatesFolder = process.env.TEMPLATES_PATH;
const scriptFolder = path.join(process.cwd());
fs.readFile(`${templatesFolder}/${fileName}`, (err, data) => {
if (!err) {
const document = {
template: data.toString(),
// add variables values below, when present in hbs file
context: {},
path: `${scriptFolder}/pdfs/${new Date().getTime()}.pdf`
};
pdf.create(document)
.then(response => {
console.log(`PDF created at: ${response.filename}`);
})
.catch(err => {
console.log(err);
});
} else {
throw Error(`An error occurred: ${err}`)
}
})