-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf.js
executable file
·64 lines (60 loc) · 2.67 KB
/
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
import fs from "fs"
import PDFDocument from 'pdfkit-table'
import QRCode from 'qrcode'
export function createPDF(box) {
// генерируем QR-code с ID коробки и сохраняем
QRCode.toFile('QR.png', [box[0].box])
let doc = new PDFDocument({margin: 30, size: 'A4'});
doc.pipe(fs.createWriteStream("./document.pdf"));
const current_box = current_box;
if(current_box.length === 50) {
;(async function () {
const table = {
title: " BOX: " + box[0].box + " ",
headers: ["N", "Serial"],
rows: [
current_box.map((serial_number, i) => [i, serial_number])
],
subtitle: "Date: " + new Date().toLocaleDateString() + " _______________________",
};
await doc.table(table, {
width: 532,
prepareHeader: () => {
doc.font("Helvetica-Bold").fontSize(8)
doc.image('QR.png', 350, 18, { width: 30, fit: [500, 200]} )
doc.image('logo.png', 22, 22, { width: 67, fit: [500, 200]} )
},
prepareRow: (row, indexColumn, indexRow, rectRow, rectCell) => {
doc.font("Helvetica").fontSize(6)
indexColumn === 0 && doc.addBackground(rectRow, 'green', 0.15)
},
});
doc.end();
})();
}
if(current_box.length === 100) {
;(async function () {
const table = {
title: " BOX: " + box[0].box + " ",
headers: ["N", "Serial", " ", "N", "Serial", " "],
rows: [
current_box.map((serial_number, i) => [i, serial_number])
],
subtitle: "Date: " + new Date().toLocaleDateString() + " _______________________",
};
await doc.table(table, {
width: 532,
prepareHeader: () => {
doc.font("Helvetica-Bold").fontSize(8)
doc.image('QR.png', 350, 18, { width: 30, fit: [500, 200]} )
doc.image('logo.png', 22, 22, { width: 67, fit: [500, 200]} )
},
prepareRow: (row, indexColumn, indexRow, rectRow, rectCell) => {
doc.font("Helvetica").fontSize(6)
indexColumn === 0 && doc.addBackground(rectRow, 'green', 0.15)
},
});
doc.end();
})();
}
}