I needed to generate some Code 128 Barcodes for Labels we neede for Amazon. As it should be simple to generate them using a code 128 font, i had a go in doing so, only to find out, that i could’t find any working Code 128 Font on the web.
I know that there are online Tools to generate the codes as images. But as i where at it i decided to make a usable code 128 font myself. The fonts are available in .svg, .ttf and .woff format.
The font and all the Tools used to genearte the font and a simple code generator example can be found on its github repository.
(See the Live Example Code Generator)
using the fonts and generator is quite simple.
load the generator script
<script src="https://cdn.rawgit.com/Holger-Will/code128/master/tools/generator.js"></script>
and in your script use the generator to turn your text into code 128 code.
var generator = new Code128Generator()
var code = generator.getCode("Your Text")
console.log(code)
this script will output an ascii string containing the start and end codes and the checksum. wich will look like this „ÑYour TextcÓ“. This code displayed with any of the code 128 fonts will print a scannable code 128 barcode. To use the font, simply download it and use it in your project, or use the CDN version:
in your css
@font-face { font-family: 'code128'; src: url('https://cdn.rawgit.com/Holger-Will/code128/master/fonts/code128.woff'); }
.barcode { font-family: code128; font-size:30px; padding:5px}
and in your html
<div class="barcode">;ÑYour TextcÓ</div>
Have Fun!