Formatting
This commit is contained in:
47
index.js
47
index.js
@ -13,8 +13,8 @@ function randomId(length) {
|
||||
//Generating random preset, to identify possible doubles
|
||||
const preset = randomId(3);
|
||||
|
||||
console.log("The radnom preset for this set is:", preset);
|
||||
console.log("Make shure this was not used before and if so, retry")
|
||||
console.log("The random preset for this set is:", preset);
|
||||
console.log("Make sure this was not used before and if so, retry");
|
||||
var etk = {};
|
||||
|
||||
for (var i = 0; i < 12 * 100; i++) {
|
||||
@ -25,12 +25,11 @@ for (var i = 0; i < 12 * 100; i++) {
|
||||
|
||||
var ets = Object.keys(etk);
|
||||
|
||||
const bluebird = require("bluebird");
|
||||
const PDFDocument = require("pdfkit");
|
||||
const doc = new PDFDocument({ size: "A4", autoFirstPage: false });
|
||||
const fs = require("fs");
|
||||
//const barcode = require("barcode");
|
||||
const bwipjs = require('bwip-js');
|
||||
const bwipjs = require("bwip-js");
|
||||
const ewidth = 277;
|
||||
const eheight = 119;
|
||||
const mgap = 8.49;
|
||||
@ -65,7 +64,7 @@ function print(xo, yo, bc) {
|
||||
doc.moveTo(xo + (ewidth / 4) * 2.4 + 5, h).lineTo(xo + ewidth - 10, h);
|
||||
doc.stroke();
|
||||
//Sid Field:
|
||||
var h = yo + (eheight / 4) + 10;
|
||||
var h = yo + eheight / 4 + 10;
|
||||
|
||||
doc.text("SchülerId", xo + (ewidth / 4) * 2.4 + 5, h + 6);
|
||||
doc.moveTo(xo + (ewidth / 4) * 2.4 + 5, h).lineTo(xo + ewidth - 10, h);
|
||||
@ -75,29 +74,33 @@ function print(xo, yo, bc) {
|
||||
var imagewidth = (ewidth / 4) * 2.2;
|
||||
var imageheight = 20;
|
||||
return new Promise((resolve, reject) => {
|
||||
bwipjs.toBuffer({
|
||||
bcid: "code128",
|
||||
text: bc,
|
||||
scale: 1,
|
||||
height: imageheight,
|
||||
width: imagewidth,
|
||||
includetext: true,
|
||||
textxalign: "center",
|
||||
textsize: 15
|
||||
}, (err, png) => {
|
||||
if (err) return console.log(err);
|
||||
doc.image(png, xo + 5, yo + 5, { height: 50, width: imagewidth });
|
||||
resolve();
|
||||
});
|
||||
bwipjs.toBuffer(
|
||||
{
|
||||
bcid: "code128",
|
||||
text: bc,
|
||||
scale: 1,
|
||||
height: imageheight,
|
||||
width: imagewidth,
|
||||
includetext: true,
|
||||
textxalign: "center",
|
||||
textsize: 15,
|
||||
},
|
||||
(err, png) => {
|
||||
if (err) return console.log(err);
|
||||
doc.image(png, xo + 5, yo + 5, { height: 50, width: imagewidth });
|
||||
resolve();
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function page(items, callback, index) { //bekommt ein array mit 12 ids
|
||||
function page(items, callback, index) {
|
||||
//bekommt ein array mit 12 ids
|
||||
doc.addPage({ margin: 0 });
|
||||
var j = 0;
|
||||
var proms = [];
|
||||
for (var i = 0; i < 6; i++) {
|
||||
if (j >= items.length) break;;
|
||||
if (j >= items.length) break;
|
||||
proms.push(print(14.15, 62.24 + i * eheight, items[j]));
|
||||
j++;
|
||||
}
|
||||
@ -124,4 +127,4 @@ function printpack(index) {
|
||||
}
|
||||
page(i, printpack, index);
|
||||
}
|
||||
printpack(0);
|
||||
printpack(0);
|
||||
|
Reference in New Issue
Block a user