Do not do this unless you do not have any other choice. Preferrably use whatever native barcode support of the printer involved, if it does not have that, just generate the barcode as vector image or bitmap with a resolution that is a integer fraction of the printers resolution. Generating correct Code128 as a SVG is about the same amount of work as generating the correct input for some sort of barcode font (the hard part is determining the switches between character sets, not generating bars from bytes).
Neat! Barcodes are much more complex that I knew before looking into it. I used JsBarcode [1] to create a special barcode that reprograms a cheap barcode scanner we got on Amazon to be able to scan both UPS and FedEx tracking numbers. It is published on CodePen [2].
This would be more interesting if you wouldn’t need to calculate checksums yourself, and could just write the barcode value. Good luck doing that with something like Reed-Solomon (QR, Data Matrix, etc.) or the shenanigans they’re doing with GS1 DataBar.