Does anyone have any experience generating EAN-13 barcodes from a string which results in a base64 encoded image or binary data?

This topic was automatically generated from Slack. You can find the original thread here.

Eyal Gershon : Hey guys im sorry if this is a newbie question as my node knowledge is limited. Does anyone have any experience generating EAN-13 barcodes from a string which results in a base64 encoded image or binary data?
I was looking at https://github.com/jshor/symbology but had an issue trying to make it work in Pipedream.

Nghia Nguyen : I think this package here might be better documented and better-featured: jsbarcode - npm

Nghia Nguyen : There’s some sample code down at the bottom, but the idea would be to generate the barcode on node-canvas and save/export the image if you want the barcode as a file.

Eyal Gershon : Thanks I will try and tinker with it,

Eyal Gershon : No matter what I do I keep seeing this error:
libuuid.so.1: cannot open shared object file: No such file or directory

Eyal Gershon : any particular reason why node-canvas returns this error? I cant get it to load properly

Nghia Nguyen : can you give me an example of a string you want to turn into an EAN-13 barcode?

Eyal Gershon : 8725651426172

Eyal Gershon : for example

Eyal Gershon : thanks for your help!..

Eyal Gershon : my idea was to create a simple web service to create this using pipedream

Nghia Nguyen : hmm

Nghia Nguyen : that EAN example isn’t valid

Nghia Nguyen : can you give me one that’s valid? for example checking here: EAN (International Article Number) validator Online

Eyal Gershon : 9780471117094

Nghia Nguyen : ```
var JsBarcode = require(“jsbarcode”);

const { DOMImplementation, XMLSerializer } = require(‘xmldom’);
const xmlSerializer = new XMLSerializer();
const document = new DOMImplementation().createDocument(‘http://www.w3.org/1999/xhtml’, ‘html’, null);
const svgNode = document.createElementNS(‘SVG namespace’, ‘svg’);

JsBarcode(svgNode, “9780471117094”, {
xmlDocument: document,
format: “EAN13”
}).options({font: “OCR-B”}) // Will affect all barcodes
.render();

return xmlSerializer.serializeToString(svgNode);

Nghia Nguyen : this returns an svg block which then you can render in HTML ->

Nghia Nguyen :

Eyal Gershon : Thank you so much!! much appreciated!

Nghia Nguyen : you can use that skeleton to create the service you’re looking to create. Maybe a pipedream endpoint gets triggered with a bunch of EAN strings you want to generate barcodes for, then you’d just loop over the code and pump out those blocks, and then do what ya want with them. If you want the base64 encoded strings you can take the string-serialized svgNode that is returned and process it through a window.btoa(stringSerializedSvgNode)