Formatting

This commit is contained in:
Fabian Stamm 2020-06-25 14:59:23 +02:00
parent 004b118488
commit 6e5e513f64
3 changed files with 64 additions and 43 deletions

7
.editorconfig Normal file
View File

@ -0,0 +1,7 @@
root=true
[*]
charset = utf-8
end_of_line = lf
indent_size = 3
indent_style = space
insert_final_newline = true

View File

@ -13,8 +13,8 @@ function randomId(length) {
//Generating random preset, to identify possible doubles //Generating random preset, to identify possible doubles
const preset = randomId(3); const preset = randomId(3);
console.log("The radnom preset for this set is:", preset); console.log("The random preset for this set is:", preset);
console.log("Make shure this was not used before and if so, retry") console.log("Make sure this was not used before and if so, retry");
var etk = {}; var etk = {};
for (var i = 0; i < 12 * 100; i++) { 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); var ets = Object.keys(etk);
const bluebird = require("bluebird");
const PDFDocument = require("pdfkit"); const PDFDocument = require("pdfkit");
const doc = new PDFDocument({ size: "A4", autoFirstPage: false }); const doc = new PDFDocument({ size: "A4", autoFirstPage: false });
const fs = require("fs"); const fs = require("fs");
//const barcode = require("barcode"); //const barcode = require("barcode");
const bwipjs = require('bwip-js'); const bwipjs = require("bwip-js");
const ewidth = 277; const ewidth = 277;
const eheight = 119; const eheight = 119;
const mgap = 8.49; 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.moveTo(xo + (ewidth / 4) * 2.4 + 5, h).lineTo(xo + ewidth - 10, h);
doc.stroke(); doc.stroke();
//Sid Field: //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.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.moveTo(xo + (ewidth / 4) * 2.4 + 5, h).lineTo(xo + ewidth - 10, h);
@ -75,7 +74,8 @@ function print(xo, yo, bc) {
var imagewidth = (ewidth / 4) * 2.2; var imagewidth = (ewidth / 4) * 2.2;
var imageheight = 20; var imageheight = 20;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
bwipjs.toBuffer({ bwipjs.toBuffer(
{
bcid: "code128", bcid: "code128",
text: bc, text: bc,
scale: 1, scale: 1,
@ -83,21 +83,24 @@ function print(xo, yo, bc) {
width: imagewidth, width: imagewidth,
includetext: true, includetext: true,
textxalign: "center", textxalign: "center",
textsize: 15 textsize: 15,
}, (err, png) => { },
(err, png) => {
if (err) return console.log(err); if (err) return console.log(err);
doc.image(png, xo + 5, yo + 5, { height: 50, width: imagewidth }); doc.image(png, xo + 5, yo + 5, { height: 50, width: imagewidth });
resolve(); 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 }); doc.addPage({ margin: 0 });
var j = 0; var j = 0;
var proms = []; var proms = [];
for (var i = 0; i < 6; i++) { 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])); proms.push(print(14.15, 62.24 + i * eheight, items[j]));
j++; j++;
} }

View File

@ -1,16 +1,16 @@
var PDFDocument = require("pdfkit"); var PDFDocument = require("pdfkit");
var doc = new PDFDocument({ size: "A4", autoFirstPage: false }); var doc = new PDFDocument({ size: "A4", autoFirstPage: false });
var fs = require("fs"); var fs = require("fs");
var bluebird = require("bluebird"); var ets = [];
var ets = []
var height = 841.89; var height = 841.89;
var width = 595.28; 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()); ets.push(i.toString());
} }
//const barcode = require("barcode"); //const barcode = require("barcode");
var bwipjs = require('bwip-js'); var bwipjs = require("bwip-js");
const margin = 40; const margin = 40;
//A4: [595.28, 841.89], //A4: [595.28, 841.89],
@ -20,7 +20,11 @@ function print(xo, yo, bc) {
xo = xo + 40; xo = xo + 40;
yo = yo + 40; yo = yo + 40;
doc.fontSize(14); 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); doc.fontSize(16);
yo += 45; yo += 45;
@ -57,7 +61,8 @@ function print(xo, yo, bc) {
var imagewidth = 240; var imagewidth = 240;
var imageheight = 20; var imageheight = 20;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
bwipjs.toBuffer({ bwipjs.toBuffer(
{
bcid: "code128", bcid: "code128",
text: bc, text: bc,
scale: 1, scale: 1,
@ -65,16 +70,22 @@ function print(xo, yo, bc) {
width: imagewidth, width: imagewidth,
includetext: true, includetext: true,
textxalign: "center", textxalign: "center",
textsize: 15 textsize: 15,
}, (err, png) => { },
(err, png) => {
if (err) return console.log(err); if (err) return console.log(err);
doc.image(png, xo + 23 - 40, h + 23, { height: 50, width: imagewidth }); doc.image(png, xo + 23 - 40, h + 23, {
resolve(); 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.addPage({ margin: 0, size: "A4" });
doc.moveTo(width / 2, 0).lineTo(width / 2, height); doc.moveTo(width / 2, 0).lineTo(width / 2, height);
doc.stroke(); doc.stroke();