Generating barcode in Retool (not scanning)

Hey everybody,
Have been building some simple tools in Retool and am having a great time with it. Barcode scanning is working great but we would love to be able to generate our own barcode's to scan into our ERP software. Does anyone have a method to do this within Retool using a custom component or an image?

Thanks

1 Like

You can use JsBarcode - Barcode generator written in JavaScript
And add the js library to either the app or your entire Retool platform.
See: Preloaded JavaScript and Libraries

1 Like

CDN link to JsBarcode: https://cdnjs.com/libraries/jsbarcode

1 Like

@ScottR could you please provide an example.
I believe that I have the JsBarcode library installed for my app, but I cant seem to get it to render.

Did you add it to the app itself or to your retool instance overall? Screenshot?

I added it to the retool instance, or atleast I think I did by adding it into the advanced pane below:

I had some help and the issues were:

  1. I tried to import the js library in the wrong place.
  2. It would be easier to return a base64encoded image from a function than try to replace an object in the dom. (add the following to the app js):
function textToBase64Barcode(text){
    var canvas = document.createElement("canvas");
    JsBarcode(canvas,text.text , {format: text.format});
    return canvas.toDataURL("image/png");
}

then in an image:
{{ textToBase64Barcode({"text":"your text","format":""}) }}

4 Likes