-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug-pdf.js
65 lines (58 loc) · 1.83 KB
/
debug-pdf.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const pdf = require("pdf-creator-node");
const fs = require("fs");
const os = require("os");
require("dotenv").config();
const tmpdirPath = os.tmpdir();
const tempdir = fs.realpathSync(tmpdirPath);
function createPdf(params, callback){
// Read HTML Template
const html = fs.readFileSync(__dirname + "/public/templates/template.html", "utf8");
//const avatar = fs.readFileSync(__dirname + `/public/assets/avatar/${params.avatar}.jpg`).toString('base64');
//const stamp = fs.readFileSync(__dirname + "/public/assets/cert/stamp.svg").toString('base64');
const wwaCert = fs.readFileSync(__dirname + `/public/assets/wwa_cert.png`).toString('base64');
let options = {
format: "A4",
orientation: "portrait",
border: "0mm",
/*
header: {
height: "45mm",
contents: '<div style="text-align: center;">Author: Shyam Hajare</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'
}
}
*/
};
let document = {
html: html,
data: {
apiurl: process.env.IS_PROD === "true" ? process.env.API_URL : process.env.ALT_API_URL,
wwaCert: wwaCert,
params: params,
},
path: `${tempdir}/wwa.pdf`,
type: "",
};
pdf.create(document, options)
.then((res) => {
console.debug(res);
callback();
})
.catch((error) => {
console.error(error);
});
}
const params = {
wwaText: "Ich notiere ein halbes Jahr lang, welche Kleider ich trage. Was ich in dieser Zeit nicht anziehe, verschenke ich oder gebe es in den Secondhand-Handel.",
wwaNumber: "D - 000001"
}
createPdf(params, () => {
console.log("PDF created")
})