27 lines
650 B
JavaScript
27 lines
650 B
JavaScript
const fs = require("fs");
|
|
const path = require("path");
|
|
const PizZip = require("pizzip");
|
|
const Docxtemplater = require("docxtemplater");
|
|
|
|
function generateInvoice(data) {
|
|
const templatePath = path.join(__dirname, "../templates/invoice_template.docx");
|
|
const content = fs.readFileSync(templatePath, "binary");
|
|
|
|
const zip = new PizZip(content);
|
|
const doc = new Docxtemplater(zip, {
|
|
paragraphLoop: true,
|
|
linebreaks: true
|
|
});
|
|
|
|
doc.render(data);
|
|
|
|
const buffer = doc.getZip().generate({
|
|
type: "nodebuffer",
|
|
compression: "DEFLATE"
|
|
});
|
|
|
|
return buffer;
|
|
}
|
|
|
|
module.exports = generateInvoice;
|