forked from t7tran/carbone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
38 lines (33 loc) · 869 Bytes
/
test.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
33
34
35
36
37
38
const carbone = require("carbone");
const fs = require("fs");
function generateReport(templatePath, data, options) {
return new Promise((resolve, reject) => {
carbone.render(templatePath, data, options, (err, result) => {
if (err) reject(err);
else resolve(result);
});
});
}
async function main() {
const data = {
firstname: "John",
lastname: "Doe",
};
const options = {
convertTo: "pdf", //can be docx, txt, ...
};
try {
const result = await generateReport(
"./node_modules/carbone/examples/simple.odt",
data,
options
);
fs.writeFileSync("result.pdf", result);
console.log("Report generated successfully: result.pdf");
} catch (err) {
console.error("Error generating report:", err);
} finally {
process.exit(); // to kill automatically LibreOffice workers
}
}
main();