-
Notifications
You must be signed in to change notification settings - Fork 0
/
badgePrint.js
124 lines (97 loc) · 2.55 KB
/
badgePrint.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
var fs = require('fs');
var PDFDocument = require('pdfkit');
const delay = require('delay');
var _ = require('lodash');
var type= "Attendee"
var lastNumber = 2942
function printParticipant(participant) {
var filenameBase = 'output/' + participant.ticketId;
console.log(participant.fullName)
// Create a document
doc = new PDFDocument({
size: [1915, 1920],
autoFirstPage: false,
});
doc.pipe(fs.createWriteStream(filenameBase + '.pdf'));
doc.addPage();
image = 'shield-' + type + '.png';
var height = doc.page.height;
var width = doc.page.height;
var maxWidth = doc.page.width - 600;
var margin = 10;
doc.image(image, 0, 0, {
height,
width,
});
// First name
doc.font('NorseBold-2Kge.otf').fontSize(180).fillColor('#ffffff');
if (doc.widthOfString(participant.fullName) > maxWidth) {
doc.fontSize(140);
if (doc.widthOfString(participant.fullName) > maxWidth) {
doc.fontSize(80);
}
}
doc.text(participant.fullName, margin, 1100, {
align: 'center',
height,
width,
});
// Company
if (participant.company) {
doc.font('NorseBold-2Kge.otf').fontSize(100).fillColor('#e46025');
if (doc.widthOfString(participant.company) > maxWidth) {
doc.fontSize(80);
if (doc.widthOfString(participant.company) > maxWidth) {
doc.fontSize(60);
}
}
doc.text(participant.company, margin, 1300, {
align: 'center',
height,
width,
});
}
// Twitter
var twitter = participant.crewType || type
doc.font('NorseBold-2Kge.otf').fontSize(80).fillColor('#ffffff');
if (doc.widthOfString(twitter) > maxWidth) {
doc.fontSize(60);
if (doc.widthOfString(twitter) > maxWidth) {
doc.fontSize(40);
}
}
doc.text(twitter, margin, 1485, {
align: 'center',
height,
width,
});
doc.end();
require('pdf-to-png')(
{
input: filenameBase + '.pdf',
output: filenameBase + '.png', // 'output/badge-' + _.snakeCase(participant.fullName) + '.png', //
scale: 0.5
},
//deleteFile(filenameBase + '.pdf')
);
}
function deleteFile(file) {
try{
var sourceUrl = file;
fs.unlinkSync(sourceUrl);
}catch(err){
console.log(err);
}
}
async function badgePrint(participants) {
for (var participant of participants) {
if (participant['fullName'] != ' ' && parseInt(participant['number']) > lastNumber) {
printParticipant(participant);
console.log('Number ' + participant['number'])
await delay(500);
}
}
}
module.exports = {
badgePrint,
};