-
Notifications
You must be signed in to change notification settings - Fork 1
/
pdf.js
58 lines (42 loc) · 1.48 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
const PDFDocument = require('pdfkit');
const fs = require('fs');
const readline = require('readline');
const sizeOf = require('image-size');
const cardInput = readline.createInterface({
input: process.stdin,
output: process.stdout
});
cardInput.question("Paste a list of cards. Example: B43,499,G42 etc etc \n", (answer) => {
var xCord = 0;
var yCord = 0;
// Create a document
const doc = new PDFDocument({ margin: 0 });
doc.pipe(fs.createWriteStream('output.pdf'));
const cardNocomma = answer.split(',');
console.log(cardNocomma)
for (let i = 0; i < cardNocomma.length; i++) {
// Trim the excess whitespace and lowercase.
cardNocomma[i] = cardNocomma[i].replace(/^\s*/, "").replace(/\s*$/, "").toLowerCase();
let x = i % 3;
xCord = 200 * x;
if (i % 3 == 0 && i != 0) {
yCord += 250
}
// Reset x and y cords on new page
if (i % 9 == 0 && i != 0) {
doc.addPage();
xCord = 0;
yCord = 0;
}
// Images might have different sizes
let dimensions = sizeOf('cards_numbers/' + cardNocomma[i] + '.png');
let rescale = 160 / dimensions.width
doc.image('cards_numbers/' + cardNocomma[i] + '.png', xCord, yCord, {
align: 'center',
valign: 'center',
scale: rescale
});
}
doc.end();
cardInput.close();
});