Initial commit

This commit is contained in:
Leon Meier 2023-06-19 22:56:18 +02:00
commit 75822bbfc0
8 changed files with 3744 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules
output.pdf

5
README.md Normal file
View File

@ -0,0 +1,5 @@
# Inventory Tag generator
```bash
node ./index.js
```

75
index.js Normal file
View File

@ -0,0 +1,75 @@
const pdf = require("pdf-creator-node");
const QRCode = require("qrcode");
const fs = require("fs");
const path = require("path");
// Read HTML Template
const html = fs.readFileSync(path.join(__dirname, "./template.html"), "utf8");
// from https://stackoverflow.com/questions/58325771/how-to-generate-random-hex-string-in-javascript
const genRanHex = (size) =>
[...Array(size)]
.map(() => Math.floor(Math.random() * 16).toString(16))
.join("");
const options = {
format: "A4",
orientation: "portrait",
border: "0mm",
};
function generate_qrcodes(urldata) {
return QRCode.toDataURL([{data: urldata, mode: 'Byte'}], { errorCorrectionLevel: 'L', margin: 0 });
}
const allPromises = [];
const promiseData = [];
for (let i = 0; i < 6 * 8; i++) {
const randData = genRanHex(8);
allPromises.push(generate_qrcodes("https://inventory.internal.thegreydiamond.de/" + randData));
promiseData.push(randData);
}
Promise.all(allPromises).then((results) => {
// console.log(results);
const data = [];
// Group qr codes into 8 per list element
for (let i = 0; i < results.length; i += 6) {
data.push({
q0: {url: results[i], data: promiseData[i]},
q1: {url: results[i + 1], data: promiseData[i + 1]},
q2: {url: results[i + 2], data: promiseData[i + 2]},
q3: {url: results[i + 3], data: promiseData[i + 3]},
q4: {url: results[i + 4], data: promiseData[i + 4]},
q5: {url: results[i + 5], data: promiseData[i + 5]},
});
}
// console.log(users);
const document = {
html: html,
data: { data: data },
path: "./output.pdf",
type: "",
};
// By default a file is created but you could switch between Buffer and Streams by using "buffer" or "stream" respectively.
/* var document = {
html: html,
data: {
users,
},
path: "./output.pdf",
type: "", // "stream" || "buffer" || "" ("" defaults to)
}; */
pdf.create(document, options)
.then((res) => {
console.log(res);
})
.catch((error) => {
console.error(error);
});
});

84
logo.svg Normal file
View File

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="14.888406mm"
height="15.975481mm"
viewBox="0 0 14.888406 15.975481"
version="1.1"
id="svg5"
inkscape:version="1.1 (c68e22c387, 2021-05-23)"
sodipodi:docname="logoMainBlack.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview7"
pagecolor="#505050"
bordercolor="#eeeeee"
borderopacity="1"
inkscape:pageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="0"
inkscape:document-units="mm"
showgrid="false"
inkscape:zoom="8"
inkscape:cx="11.3125"
inkscape:cy="25.3125"
inkscape:window-width="1920"
inkscape:window-height="1017"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="layer1"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0" />
<defs
id="defs2">
<rect
x="30.260479"
y="17.651945"
width="130.40826"
height="114.55753"
id="rect2168" />
</defs>
<g
inkscape:label="Ebene 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-0.3489323,-0.36586906)">
<text
xml:space="preserve"
transform="matrix(0.26458333,0,0,0.26458333,-7.6262914,-5.953125)"
id="text2166"
style="font-style:normal;font-weight:normal;font-size:40px;line-height:1.25;font-family:sans-serif;white-space:pre;shape-inside:url(#rect2168);fill:#000000;fill-opacity:1;stroke:none"><tspan
x="30.259766"
y="53.042969"
id="tspan8490">T</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:10.5833px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="2.4501607"
y="12.656869"
id="text6046"><tspan
sodipodi:role="line"
id="tspan6044"
style="stroke-width:0.264583"
x="2.4501607"
y="12.656869">G</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:10.5833px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="7.713273"
y="16.341351"
id="text8012"><tspan
sodipodi:role="line"
id="tspan8010"
style="stroke-width:0.264583"
x="7.713273"
y="16.341351">D</tspan></text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.8 KiB

2071
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

6
package.json Normal file
View File

@ -0,0 +1,6 @@
{
"dependencies": {
"pdf-creator-node": "^2.3.5",
"qrcode": "^1.5.3"
}
}

1398
qrcode.js Normal file

File diff suppressed because it is too large Load Diff

103
template.html Normal file
View File

@ -0,0 +1,103 @@
<!DOCTYPE html>
<html>
<head>
<title>Node PDF Creator</title>
<style>
html,
body {
height: 296mm;
width: 212mm;
margin: 0px;
padding: 0px;
background-color: #ffffff;
overflow: hidden;
}
table {
margin: 0px;
padding: 0px;
border-collapse: collapse;
}
td {
text-align: center;
border: 1px black;
border-style: none dashed none none;
height: 37mm;
width: 35mm;
padding: 0px;
background-color: rgb(255, 255, 255)
}
tr {
margin: 0px;
}
.qrcode {
padding: 0px;
margin: 0px;
height: 2cm;
width: 2cm;
}
p {
font-family: monospace;
margin: 0px;
padding: 0px;
/*background-color: rgb(0, 0, 0);*/
height: fit-content;
text-align: center;
vertical-align: top;
font-size: 8pt;
}
</style>
</head>
<body>
<div class="container">
<table>
<tbody>
{{#each data}}
<tr>
<td>
<p><strong>INVENTAR</strong></p>
<img class="qrcode" src="{{this.q0.url}}">
<p><strong>SKU {{this.q0.data}}</strong></p>
</td>
<td>
<p><strong>INVENTAR</strong></p>
<img class="qrcode" src="{{this.q1.url}}">
<p><strong>SKU {{this.q1.data}}</strong></p>
</td>
<td>
<p><strong>INVENTAR</strong></p>
<img class="qrcode" src="{{this.q2.url}}">
<p><strong>SKU {{this.q2.data}}</strong></p>
</td>
<td>
<p><strong>INVENTAR</strong></p>
<img class="qrcode" src="{{this.q3.url}}">
<p><strong>SKU {{this.q3.data}}</strong></p>
</td>
<td>
<p><strong>INVENTAR</strong></p>
<img class="qrcode" src="{{this.q4.url}}">
<p><strong>SKU {{this.q4.data}}</strong></p>
</td>
<td>
<p><strong>INVENTAR</strong></p>
<img class="qrcode" src="{{this.q5.url}}">
<p><strong>SKU {{this.q5.data}}</strong></p>
</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
</body>
</html>