First Commit

This commit is contained in:
Fabian Stamm 2018-05-29 15:17:24 +02:00
commit 004b118488
8 changed files with 1028 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
node_modules
etiketten*
student_form.pdf

112
briefe.js.old Normal file
View File

@ -0,0 +1,112 @@
var PDFDocument = require("pdfkit");
var doc = new PDFDocument({ size: "letter", autoFirstPage: false });
var fs = require("fs");
var bluebird = require("bluebird");
var sid = require("shortid");
var ets = [];
//sid.characters("ABCDESFHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890");
for (var i = 0; i < 12 * 10; i++) {
ets.push(sid.generate());
}
console.log(ets);
//const barcode = require("barcode");
var bwipjs = require('bwip-js');
const ewidth = 277;
const eheight = 119;
const mgap = 8.49;
doc.pipe(fs.createWriteStream(__dirname + "/pdf.pdf"));
//A4 2480 x 3508
//doc.addPage({margin: 0});
//S = 1134
//A4: [595.28, 841.89],
// 28.29
//o w:14,15
//o h: 62,24
// <------------> (277)
// |
// | (119)
// |
function print(xo, yo, bc) {
//doc.rect(xo, yo, ewidth, eheight);
//doc.stroke();
//Name Field
doc.fontSize(16);
var h = yo + (eheight / 4) * 3;
doc.text("Name", xo + 5, h + 6);
doc.moveTo(xo + 5, h).lineTo(xo + (ewidth / 4) * 2.2, h);
doc.stroke();
//Price Field;
doc.text("Preis", xo + (ewidth / 4) * 2.4 + 5, h + 6);
doc.moveTo(xo + (ewidth / 4) * 2.4 + 5, h).lineTo(xo + ewidth - 10, h);
doc.stroke();
//Sid Field:
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);
doc.stroke();
//Barcode:
var imagewidth = (ewidth / 4) * 2.2;
var imageheight = 20;
return new Promise((resolve, reject) => {
console.log(imageheight, imagewidth);
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
doc.addPage({ margin: 0 });
var j = 0;
var proms = [];
for (var i = 0; i < 6; i++) {
if (j >= items.length) break;;
proms.push(print(14.15, 62.24 + i * eheight, items[j]));
j++;
}
for (var i = 0; i < 6; i++) {
if (j >= items.length) break;
proms.push(print(14.15 + ewidth + mgap, 62.24 + i * eheight, items[j]));
j++;
}
Promise.all(proms).then(() => {
callback(index + 12);
});
}
function printpack(index) {
if (index >= ets.length) {
doc.end();
return;
}
var i = [];
for (var g = 0; g < 12; g++) {
if (index + g >= ets.length) break;
i.push(ets[index + g]);
}
page(i, printpack, index);
}
printpack(0);

1
gesamtgewinn.js Normal file
View File

@ -0,0 +1 @@
db.getCollection('books').aggregate({$match:{$or:[{state:1}, {state:0}]}}, { $group: {_id:null, sum : { $sum: "$price" }}})

1
gesamtgewinn_count.js Normal file
View File

@ -0,0 +1 @@
db.getCollection('books').aggregate({$match:{$or:[{state:1}, {state:0}]}}, { $count:"count"})

127
index.js Normal file
View File

@ -0,0 +1,127 @@
const possibleChars = "ABCDESFHIJKLMNOPQRSTUVWXYZ1234567890";
const possibleCharsLength = possibleChars.length;
function randomId(length) {
let ans = "";
for (; length > 0; length--) {
let idx = Math.floor(Math.random() * possibleCharsLength);
ans += possibleChars[idx];
}
return ans;
}
//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")
var etk = {};
for (var i = 0; i < 12 * 100; i++) {
let id = preset + randomId(6);
if (etk[id] !== undefined) i--;
else etk[id] = 1;
}
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 ewidth = 277;
const eheight = 119;
const mgap = 8.49;
doc.pipe(fs.createWriteStream(__dirname + "/etiketten.pdf"));
//A4 2480 x 3508
//doc.addPage({margin: 0});
//S = 1134
//A4: [595.28, 841.89],
// 28.29
//o w:14,15
//o h: 62,24
// <------------> (277)
// |
// | (119)
// |
function print(xo, yo, bc) {
//doc.rect(xo, yo, ewidth, eheight);
//doc.stroke();
//Name Field
doc.fontSize(16);
var h = yo + (eheight / 4) * 3;
doc.text("Name", xo + 5, h + 6);
doc.moveTo(xo + 5, h).lineTo(xo + (ewidth / 4) * 2.2, h);
doc.stroke();
//Price Field;
doc.text("Preis", xo + (ewidth / 4) * 2.4 + 5, h + 6);
doc.moveTo(xo + (ewidth / 4) * 2.4 + 5, h).lineTo(xo + ewidth - 10, h);
doc.stroke();
//Sid Field:
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);
doc.stroke();
//Barcode:
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();
});
});
}
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;;
proms.push(print(14.15, 62.24 + i * eheight, items[j]));
j++;
}
for (var i = 0; i < 6; i++) {
if (j >= items.length) break;
proms.push(print(14.15 + ewidth + mgap, 62.24 + i * eheight, items[j]));
j++;
}
Promise.all(proms).then(() => {
callback(index + 12);
});
}
function printpack(index) {
if (index >= ets.length) {
doc.end();
return;
}
var i = [];
for (var g = 0; g < 12; g++) {
if (index + g >= ets.length) break;
i.push(ets[index + g]);
}
page(i, printpack, index);
}
printpack(0);

642
package-lock.json generated Normal file
View File

@ -0,0 +1,642 @@
{
"name": "etikettengenerator",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"acorn": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-1.2.2.tgz",
"integrity": "sha1-yM4n3grMdtiW0rH6099YjZ6C8BQ="
},
"amdefine": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz",
"integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=",
"optional": true
},
"argv": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/argv/-/argv-0.0.2.tgz",
"integrity": "sha1-7L0W+JSbFXGDcRsb2jNPN4QBhas="
},
"array-parallel": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/array-parallel/-/array-parallel-0.1.3.tgz",
"integrity": "sha1-j3hTCJJu1apHjEfmTRszS2wMlH0="
},
"array-series": {
"version": "0.1.5",
"resolved": "https://registry.npmjs.org/array-series/-/array-series-0.1.5.tgz",
"integrity": "sha1-3103v8XC7wdV4qpPkv6ufUtaly8="
},
"ast-transform": {
"version": "0.0.0",
"resolved": "https://registry.npmjs.org/ast-transform/-/ast-transform-0.0.0.tgz",
"integrity": "sha1-dJRAWIh9goPhidlUYAlHvJj+AGI=",
"requires": {
"escodegen": "~1.2.0",
"esprima": "~1.0.4",
"through": "~2.3.4"
},
"dependencies": {
"escodegen": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.2.0.tgz",
"integrity": "sha1-Cd55Z3kcyVi3+Jot220jRRrzJ+E=",
"requires": {
"esprima": "~1.0.4",
"estraverse": "~1.5.0",
"esutils": "~1.0.0",
"source-map": "~0.1.30"
}
},
"esprima": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-1.0.4.tgz",
"integrity": "sha1-n1V+CPw7TSbs6d00+Pv0drYlha0="
}
}
},
"ast-types": {
"version": "0.7.8",
"resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.7.8.tgz",
"integrity": "sha1-kC0uDWDQcb3NRtwRXhgJ7RHBOKk="
},
"babel-runtime": {
"version": "6.23.0",
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.23.0.tgz",
"integrity": "sha1-CpSJ8UTecO+zzkMArM2zKeL8VDs=",
"requires": {
"core-js": "^2.4.0",
"regenerator-runtime": "^0.10.0"
}
},
"barcode": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/barcode/-/barcode-0.1.0.tgz",
"integrity": "sha1-SbFjFQgUo/P7D6DAqih00ooPONc=",
"requires": {
"gm": "1.16.0"
}
},
"base64-js": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.2.0.tgz",
"integrity": "sha1-o5mS1yNYSBGYK+XikLtqU9hnAPE="
},
"bluebird": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.0.tgz",
"integrity": "sha1-eRQg1/VR7qKJdFOop3ZT+WYG1nw="
},
"brfs": {
"version": "1.4.3",
"resolved": "https://registry.npmjs.org/brfs/-/brfs-1.4.3.tgz",
"integrity": "sha1-22ddb16SPm3wh/ylhZyQkKrtMhY=",
"requires": {
"quote-stream": "^1.0.1",
"resolve": "^1.1.5",
"static-module": "^1.1.0",
"through2": "^2.0.0"
}
},
"brotli": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/brotli/-/brotli-1.3.2.tgz",
"integrity": "sha1-UlqcrU/LqWR119OI9q7LE+7VL0Y=",
"requires": {
"base64-js": "^1.1.2"
}
},
"browser-resolve": {
"version": "1.11.2",
"resolved": "https://registry.npmjs.org/browser-resolve/-/browser-resolve-1.11.2.tgz",
"integrity": "sha1-j/CbCixCFxihBRwmCzLkj0QpOM4=",
"requires": {
"resolve": "1.1.7"
},
"dependencies": {
"resolve": {
"version": "1.1.7",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz",
"integrity": "sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs="
}
}
},
"browserify-optional": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/browserify-optional/-/browserify-optional-1.0.0.tgz",
"integrity": "sha1-IM96see/AUy/Y3gtNddbYtq0tvE=",
"requires": {
"ast-transform": "0.0.0",
"ast-types": "^0.7.0",
"browser-resolve": "^1.8.1"
}
},
"buffer-equal": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/buffer-equal/-/buffer-equal-0.0.1.tgz",
"integrity": "sha1-kbx0sR6kBbyRa8aqkI+q+ltKrEs="
},
"bwip-js": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/bwip-js/-/bwip-js-1.3.3.tgz",
"integrity": "sha1-FvifRdfzwXiiBHgL/FX8ukOoT68=",
"requires": {
"argv": "0.0.2"
}
},
"clone": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/clone/-/clone-1.0.2.tgz",
"integrity": "sha1-Jgt6meux7f4kdTgXX3gyQ8sZ0Uk="
},
"concat-stream": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.0.tgz",
"integrity": "sha1-CqxmL9Ur54lk1VMvaUeE5wEQrPc=",
"requires": {
"inherits": "^2.0.3",
"readable-stream": "^2.2.2",
"typedarray": "^0.0.6"
}
},
"core-js": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-2.4.1.tgz",
"integrity": "sha1-TekR5mew6ukSTjQlS1OupvxhjT4="
},
"core-util-is": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"debug": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-0.7.0.tgz",
"integrity": "sha1-9b4F7AQ0yZLXmUDlCyaVz7LgGwg="
},
"deep-equal": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz",
"integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU="
},
"dfa": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/dfa/-/dfa-1.1.0.tgz",
"integrity": "sha1-0wIYvRDQMPpCHfPrvIIoVGOjF4E=",
"requires": {
"babel-runtime": "^6.11.6"
}
},
"duplexer2": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.0.2.tgz",
"integrity": "sha1-xhTc9n4vsUmVqRcR5aYX6KYKMds=",
"requires": {
"readable-stream": "~1.1.9"
},
"dependencies": {
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"readable-stream": {
"version": "1.1.14",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
}
}
},
"escodegen": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.3.3.tgz",
"integrity": "sha1-8CQBb1qI4Eb9EgBQVek5gC5sXyM=",
"requires": {
"esprima": "~1.1.1",
"estraverse": "~1.5.0",
"esutils": "~1.0.0",
"source-map": "~0.1.33"
}
},
"esprima": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-1.1.1.tgz",
"integrity": "sha1-W28VR/TRAuZw4UDFCb5ncdautUk="
},
"estraverse": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/estraverse/-/estraverse-1.5.1.tgz",
"integrity": "sha1-hno+jlip+EYYr7bC3bzZFrfLr3E="
},
"esutils": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/esutils/-/esutils-1.0.0.tgz",
"integrity": "sha1-gVHTWOIMisx/t0XnRywAJf5JZXA="
},
"falafel": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/falafel/-/falafel-1.2.0.tgz",
"integrity": "sha1-wY0k71CRF0pJfzGM0ksCaiXN2rQ=",
"requires": {
"acorn": "^1.0.3",
"foreach": "^2.0.5",
"isarray": "0.0.1",
"object-keys": "^1.0.6"
},
"dependencies": {
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
}
}
},
"fontkit": {
"version": "1.7.6",
"resolved": "https://registry.npmjs.org/fontkit/-/fontkit-1.7.6.tgz",
"integrity": "sha1-uvMGWiTslsO5OxNz6kRbIer/Q1M=",
"requires": {
"babel-runtime": "^6.11.6",
"brfs": "^1.4.0",
"brotli": "^1.2.0",
"browserify-optional": "^1.0.0",
"clone": "^1.0.1",
"deep-equal": "^1.0.0",
"dfa": "^1.0.0",
"restructure": "^0.5.3",
"tiny-inflate": "^1.0.2",
"unicode-properties": "^1.0.0",
"unicode-trie": "^0.3.0"
}
},
"foreach": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz",
"integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k="
},
"function-bind": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.0.tgz",
"integrity": "sha1-FhdnFMgBeY5Ojyz391KUZ7tKV3E="
},
"gm": {
"version": "1.16.0",
"resolved": "https://registry.npmjs.org/gm/-/gm-1.16.0.tgz",
"integrity": "sha1-Kz03sl+zSShugpvxzPCX9N5Puog=",
"requires": {
"array-parallel": "~0.1.0",
"array-series": "~0.1.0",
"debug": "0.7.0",
"stream-to-buffer": "~0.0.1",
"through": "~2.3.1"
}
},
"has": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.1.tgz",
"integrity": "sha1-hGFzP1OLCDfJNh45qauelwTcLyg=",
"requires": {
"function-bind": "^1.0.2"
}
},
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
},
"isarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
},
"js-shortid": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/js-shortid/-/js-shortid-0.1.1.tgz",
"integrity": "sha1-0XSSiUb5rsRjqTW4oM+MGbZ739Y="
},
"linebreak": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/linebreak/-/linebreak-0.3.0.tgz",
"integrity": "sha1-BSZICmLAW9Z58+nZmDDgnGp9DtY=",
"requires": {
"base64-js": "0.0.8",
"brfs": "^1.3.0",
"unicode-trie": "^0.3.0"
},
"dependencies": {
"base64-js": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-0.0.8.tgz",
"integrity": "sha1-EQHpVE9KdrG8OybUUsqW16NeeXg="
}
}
},
"minimist": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
},
"object-inspect": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-0.4.0.tgz",
"integrity": "sha1-9RV8EWwUVbJDsG7pdwM5LFrYn+w="
},
"object-keys": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.0.11.tgz",
"integrity": "sha1-xUYBd4rVYPEULODgG8yotW0TQm0="
},
"pako": {
"version": "0.2.9",
"resolved": "https://registry.npmjs.org/pako/-/pako-0.2.9.tgz",
"integrity": "sha1-8/dSL073gjSNqBYbrZ7P1Rv4OnU="
},
"path-parse": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz",
"integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME="
},
"pdfkit": {
"version": "0.8.2",
"resolved": "https://registry.npmjs.org/pdfkit/-/pdfkit-0.8.2.tgz",
"integrity": "sha1-fHtWlwWO42dwUykttmC62UjQlyo=",
"requires": {
"fontkit": "^1.0.0",
"linebreak": "^0.3.0",
"png-js": ">=0.1.0"
}
},
"png-js": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/png-js/-/png-js-0.1.1.tgz",
"integrity": "sha1-HMfCEjA6yr50Jj7DrHgAlYAkLZM="
},
"process-nextick-args": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
"integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M="
},
"quote-stream": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/quote-stream/-/quote-stream-1.0.2.tgz",
"integrity": "sha1-hJY/jJwmuULhU/7rU6rnRlK34LI=",
"requires": {
"buffer-equal": "0.0.1",
"minimist": "^1.1.3",
"through2": "^2.0.0"
}
},
"readable-stream": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.0.tgz",
"integrity": "sha512-c7KMXGd4b48nN3OJ1U9qOsn6pXNzf6kLd3kdZCkg2sxAcoiufInqF0XckwEnlrcwuaYwonlNK8GQUIOC/WC7sg==",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.3",
"isarray": "~1.0.0",
"process-nextick-args": "~1.0.6",
"safe-buffer": "~5.1.0",
"string_decoder": "~1.0.0",
"util-deprecate": "~1.0.1"
}
},
"regenerator-runtime": {
"version": "0.10.5",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz",
"integrity": "sha1-M2w+/BIgrc7dosn6tntaeVWjNlg="
},
"resolve": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.3.3.tgz",
"integrity": "sha1-ZVkHw0aahoDcLeOidaj91paR8OU=",
"requires": {
"path-parse": "^1.0.5"
}
},
"restructure": {
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/restructure/-/restructure-0.5.4.tgz",
"integrity": "sha1-9U591WNZD7NP1r9Vh2EJrsyyjeg=",
"requires": {
"browserify-optional": "^1.0.0"
}
},
"safe-buffer": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.0.tgz",
"integrity": "sha512-aSLEDudu6OoRr/2rU609gRmnYboRLxgDG1z9o2Q0os7236FwvcqIOO8r8U5JUEwivZOhDaKlFO4SbPTJYyBEyQ=="
},
"shallow-copy": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/shallow-copy/-/shallow-copy-0.0.1.tgz",
"integrity": "sha1-QV9CcC1z2BAzApLMXuhurhoRoXA="
},
"shortid": {
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/shortid/-/shortid-2.2.8.tgz",
"integrity": "sha1-AzsRfWoul1gE9vCWnb59PQs1UTE="
},
"source-map": {
"version": "0.1.43",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.43.tgz",
"integrity": "sha1-wkvBRspRfBRx9drL4lcbK3+eM0Y=",
"optional": true,
"requires": {
"amdefine": ">=0.0.4"
}
},
"static-eval": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/static-eval/-/static-eval-0.2.4.tgz",
"integrity": "sha1-t9NNg4k3uWn5ZBygfUj47eJj6ns=",
"requires": {
"escodegen": "~0.0.24"
},
"dependencies": {
"escodegen": {
"version": "0.0.28",
"resolved": "https://registry.npmjs.org/escodegen/-/escodegen-0.0.28.tgz",
"integrity": "sha1-Dk/xcV8yh3XWyrUaxEpAbNer/9M=",
"requires": {
"esprima": "~1.0.2",
"estraverse": "~1.3.0",
"source-map": ">= 0.1.2"
}
},
"esprima": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-1.0.4.tgz",
"integrity": "sha1-n1V+CPw7TSbs6d00+Pv0drYlha0="
},
"estraverse": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/estraverse/-/estraverse-1.3.2.tgz",
"integrity": "sha1-N8K4k+8T1yPydth41g2FNRUqbEI="
}
}
},
"static-module": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/static-module/-/static-module-1.3.2.tgz",
"integrity": "sha1-Mp+58iOlZiZr2nGEO32TLHZxdPM=",
"requires": {
"concat-stream": "~1.6.0",
"duplexer2": "~0.0.2",
"escodegen": "~1.3.2",
"falafel": "^1.0.0",
"has": "^1.0.0",
"object-inspect": "~0.4.0",
"quote-stream": "~0.0.0",
"readable-stream": "~1.0.27-1",
"shallow-copy": "~0.0.1",
"static-eval": "~0.2.0",
"through2": "~0.4.1"
},
"dependencies": {
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
},
"object-keys": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/object-keys/-/object-keys-0.4.0.tgz",
"integrity": "sha1-KKaq50KN0sOpLz2V8hM13SBOAzY="
},
"quote-stream": {
"version": "0.0.0",
"resolved": "https://registry.npmjs.org/quote-stream/-/quote-stream-0.0.0.tgz",
"integrity": "sha1-zeKelMQJsW4Z3HCYuJtmWPlyHTs=",
"requires": {
"minimist": "0.0.8",
"through2": "~0.4.1"
}
},
"readable-stream": {
"version": "1.0.34",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz",
"integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
},
"through2": {
"version": "0.4.2",
"resolved": "https://registry.npmjs.org/through2/-/through2-0.4.2.tgz",
"integrity": "sha1-2/WGYDEVHsg1K7bE22SiKSqEC5s=",
"requires": {
"readable-stream": "~1.0.17",
"xtend": "~2.1.1"
}
},
"xtend": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-2.1.2.tgz",
"integrity": "sha1-bv7MKk2tjmlixJAbM3znuoe10os=",
"requires": {
"object-keys": "~0.4.0"
}
}
}
},
"stream-to-buffer": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/stream-to-buffer/-/stream-to-buffer-0.0.1.tgz",
"integrity": "sha1-q0g9WaHKcYMt43miVfRltmWvRcE="
},
"string_decoder": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.2.tgz",
"integrity": "sha1-sp4fThEl+pehA4K4pTNze3SR4Xk=",
"requires": {
"safe-buffer": "~5.0.1"
},
"dependencies": {
"safe-buffer": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.0.1.tgz",
"integrity": "sha1-0mPKVGls2KMGtcplUekt5XkY++c="
}
}
},
"through": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU="
},
"through2": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/through2/-/through2-2.0.3.tgz",
"integrity": "sha1-AARWmzfHx0ujnEPzzteNGtlBQL4=",
"requires": {
"readable-stream": "^2.1.5",
"xtend": "~4.0.1"
}
},
"tiny-inflate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/tiny-inflate/-/tiny-inflate-1.0.2.tgz",
"integrity": "sha1-k9nez/yIBb1X6uQxDwt0Xptvs6c="
},
"typedarray": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
},
"unicode-properties": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/unicode-properties/-/unicode-properties-1.1.0.tgz",
"integrity": "sha1-epbu9J91aC6mnSMV7smsQ//fAME=",
"requires": {
"brfs": "^1.4.0",
"unicode-trie": "^0.3.0"
}
},
"unicode-trie": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/unicode-trie/-/unicode-trie-0.3.1.tgz",
"integrity": "sha1-1nHd3YkQGgi6w3tqUWEBBgIFIIU=",
"requires": {
"pako": "^0.2.5",
"tiny-inflate": "^1.0.0"
}
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
},
"xtend": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",
"integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68="
}
}
}

19
package.json Normal file
View File

@ -0,0 +1,19 @@
{
"name": "etikettengenerator",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"barcode": "^0.1.0",
"bluebird": "^3.5.0",
"bwip-js": "^1.3.3",
"js-shortid": "^0.1.1",
"pdfkit": "^0.8.2",
"shortid": "^2.2.8"
}
}

123
students.js Normal file
View File

@ -0,0 +1,123 @@
var PDFDocument = require("pdfkit");
var doc = new PDFDocument({ size: "A4", autoFirstPage: false });
var fs = require("fs");
var bluebird = require("bluebird");
var ets = []
var height = 841.89;
var width = 595.28;
for (var i = 2000; i < 4 * 100 + 2000; i++) {
ets.push(i.toString());
}
//const barcode = require("barcode");
var bwipjs = require('bwip-js');
const margin = 40;
//A4: [595.28, 841.89],
// 28.29
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.fontSize(16);
yo += 45;
var h = yo + 40;
doc.moveTo(xo, h).lineTo(xo + 180, h);
doc.text("Vorame", xo, h + 5);
doc.stroke();
h += 50;
doc.moveTo(xo, h).lineTo(xo + 180, h);
doc.text("Nachname", xo, h + 5);
doc.stroke();
h += 50;
doc.moveTo(xo, h).lineTo(xo + 180, h);
doc.text("Klasse", xo, h + 5);
doc.stroke();
h += 50;
doc.moveTo(xo, h).lineTo(xo + 180, h);
doc.text("Telefon", xo, h + 5);
doc.stroke();
h += 50;
doc.moveTo(xo, h).lineTo(xo + 180, h);
doc.text("E-Mail", xo, h + 5);
doc.stroke();
//doc.rect(xo, yo, ewidth, eheight);
//doc.stroke();
//return new Promise((resolve)=>{resolve()});
//Barcode:
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();
});
});
}
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();
doc.moveTo(0, height / 2).lineTo(width, height / 2);
doc.stroke();
var i = 0;
var proms = [];
if (i < items.length) {
proms.push(print(0, 0, items[0]));
i++;
}
if (i < items.length) {
proms.push(print(width / 2, 0, items[1]));
i++;
}
if (i < items.length) {
proms.push(print(0, height / 2, items[2]));
i++;
}
if (i < items.length) {
proms.push(print(width / 2, height / 2, items[3]));
i++;
}
Promise.all(proms).then(() => {
callback(index + 4);
});
}
function printpack(index) {
if (index >= ets.length) {
doc.pipe(fs.createWriteStream(__dirname + "/student_form.pdf"));
doc.end();
return;
}
var i = [];
for (var g = 0; g < 4; g++) {
if (index + g >= ets.length) break;
i.push(ets[index + g]);
}
page(i, printpack, index);
}
printpack(0);