-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvendingGenorator.js
85 lines (73 loc) · 2.38 KB
/
vendingGenorator.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
var express = require('express');
var paper = require('paper');
var path = require('path');
var fs = require('fs');
var styles = require('./models/Styles');
var Printer = require('node-printer');
var rand = require('random-seed').create();
// creating a seed based on the current unix timestamp
var seedNum = Math.floor(Date.now() / 1000);
var SEED = seedNum.toString();
// setting the seed to the random generator
rand.seed(SEED);
var WIDTH= 595,HEIGHT = 842;
// list of all the styles
// TODO: update it from being numbers to being a string of the names
var stylesIndex = [1,2,3];
var type = stylesIndex[Math.floor(rand(stylesIndex.length))];
// this is the data
var cardName = ' No Name';
process.argv.forEach(function (val, index, array) {
if(index === 2) {
cardName = val;
}
});
var imageBase64 = "";
switch(type) {
case 1:
imageBase64 = styles.colorSquare(WIDTH,HEIGHT,rand);
break;
case 2:
imageBase64 = styles.feet(WIDTH, HEIGHT, rand, true, cardName);
case 3:
imageBase64 = styles.linesWithNoise(WIDTH,HEIGHT,rand);
break;
default:
break;
}
// res.render('index', { image: imageBase64, seed: SEED });
// var svg = imageBase64.exportSVG({ asString: true });
// fs.writeFile(path.resolve('./out.pdf'), imageBase64.toBuffer(), function (err) {
// if (err)
// throw err;
// console.log('Saved!');
// });
function print() {
var options = {
media: 'Custom.200x600mm',
n: 3
};
// Get available printers list
Printer.list();
// Create a new Pinter from available devices
var printer = new Printer(Printer.list()[0]);
// Print from a buffer, file path or text
var fileBuffer = fs.readFileSync('../svgs/out.svg');
var jobFromBuffer = printer.printBuffer(fileBuffer);
//
// var filePath = 'package.json';
// var jobFromFile = printer.printFile(filePath);
//
// var text = 'Print text directly, when needed: e.g. barcode printers'
// var jobFromText = printer.printText(text);
// Cancel a job
// jobFromFile.cancel();
// Listen events from job
jobFromBuffer.once('sent', function() {
console.log('Job ' + jobFromBuffer.identifier + 'has been sent');
jobFromBuffer.on('completed', function() {
console.log('Job ' + jobFromBuffer.identifier + 'has been printed');
jobFromBuffer.removeAllListeners();
});
});
}