diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..17c69d1 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +root=true +[*] +charset = utf-8 +end_of_line = lf +indent_size = 3 +indent_style = space +insert_final_newline = true \ No newline at end of file diff --git a/index.js b/index.js index 3b733f8..c1bfb37 100644 --- a/index.js +++ b/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); \ No newline at end of file +printpack(0); diff --git a/students.js b/students.js index 8dfa38c..093e9a3 100644 --- a/students.js +++ b/students.js @@ -1,16 +1,16 @@ var PDFDocument = require("pdfkit"); var doc = new PDFDocument({ size: "A4", autoFirstPage: false }); var fs = require("fs"); -var bluebird = require("bluebird"); -var ets = [] +var ets = []; var height = 841.89; var width = 595.28; -for (var i = 2000; i < 4 * 100 + 2000; i++) { +const offset = 4000; +for (var i = offset; i < 4 * 100 + offset; i++) { ets.push(i.toString()); } //const barcode = require("barcode"); -var bwipjs = require('bwip-js'); +var bwipjs = require("bwip-js"); const margin = 40; //A4: [595.28, 841.89], @@ -20,7 +20,11 @@ function print(xo, yo, bc) { xo = xo + 40; yo = yo + 40; doc.fontSize(14); - doc.text("Bitte alle Felder leserlich ausfüllen. \nDie Schüler-ID bitte auf \nALLE Bücher schreiben!!", xo, yo); + doc.text( + "Bitte alle Felder leserlich ausfüllen. \nDie Nummer unten bitte auf ALLE \nBücher schreiben!!", + xo, + yo + ); doc.fontSize(16); yo += 45; @@ -57,24 +61,31 @@ function print(xo, yo, bc) { var imagewidth = 240; 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 + 23 - 40, h + 23, { 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 + 23 - 40, h + 23, { + 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, size: "A4" }); doc.moveTo(width / 2, 0).lineTo(width / 2, height); doc.stroke(); @@ -120,4 +131,4 @@ function printpack(index) { } page(i, printpack, index); } -printpack(0); \ No newline at end of file +printpack(0);