dry-node
Version:
Initialiseur de structure Node Express typée et modulaire
61 lines (51 loc) • 1.75 kB
JavaScript
import fs from "fs";
const pdf = require("pdf-creator-node");
const hbs = require('handlebars');
const DryHelperHandlebar = require("./../dry-functions/dry-helper-handlebar.function");
const DryGeneratePdfFunction = async options => {
// let html = fs.readFileSync("./views/templates/ticket.handlebars", "utf8");
hbs.registerHelper("dateFormat", function (date) {
return new DryHelperHandlebar().getDateFormattedFrench(date);
});
hbs.registerHelper("dateFormatTime", function (date) {
return new DryHelperHandlebar().getDateTimeFormattedFrench(date);
});
hbs.registerHelper("data", function (data) {
return data;
});
const optionsPdf = {
format: "A4",
orientation: "portrait",
border: "10mm",
header: {
height: "45mm",
contents: '<div style="text-align: center;">'+ options.header+'</div>'
},
footer: {
height: "28mm",
contents: {
first: 'Cover page',
2: 'Second page', // Any page number is working. 1-based index
default: '<span style="color: #444;">{{page}}</span>/<span>{{pages}}</span>', // fallback value
last: 'Last Page'
}
}
};
const document = {
html: options.html,
data: options.data,
path: "./public/pdfs/" + options.nameFile,
type: "",
};
await pdf
.create(document, optionsPdf)
.then((res) => {
return res
})
.catch((error) => {
});
return {
fileDownload: options.nameFile
}
}
module.exports = DryGeneratePdfFunction;