Skip to content

Commit

Permalink
Merge pull request #111 from pagopa/rework-datamatrix-helper
Browse files Browse the repository at this point in the history
feat: reworked datamatrix helper to use bwip-js
  • Loading branch information
jacopocarlini authored Jun 5, 2024
2 parents 23c9e37 + 5cc5458 commit 69c1552
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"adm-zip": "^0.5.10",
"applicationinsights": "^1.7.4",
"axios": "^1.5.0",
"bitgener": "^1.2.12",
"bwip-js": "^4.3.2",
"chromium": "^3.0.3",
"express": "^4.18.2",
"fs-extra": "^11.1.1",
Expand Down
45 changes: 19 additions & 26 deletions node/pdf-generate/helpers/notices/genDataMatrix.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
const bitgener = require('bitgener');
const { v4: uuidv4 } = require("uuid");
const path = require('path');
const bwipjs = require('bwip-js');
const fs = require('fs');

function genDataMatrix(data, saveDir) {
const filename = path.join(
saveDir,uuidv4()+".svg");
bitgener({
data: data,
type: 'datamatrix',
output: filename,
encoding: 'utf8',
rectangular: false,
padding: 0,
width: 256,
height: 256,
original2DSize: false,
color: 'black',
opacity: 1,
bgColor: '#F7931A',
bgOpacity: 0,
hri: {
show: false
}
}).then((ret) => {
console.log(ret);
function genDataMatrix(data, path) {
const trimmedData = data.replaceAll(' ', '');

let svg = bwipjs.toSVG({
bcid: 'datamatrix',
text: data,
width: 256,
height: 256,
padding: 0,
scale: 3,
includetext: false,
textxalign: 'center',
});

return filename;
const filePath = path + "/" + trimmedData+".svg";
fs.writeFileSync(filePath, svg);

return filePath;

}

module.exports = genDataMatrix;

0 comments on commit 69c1552

Please sign in to comment.