You can try the Libre Code128 font (free) at
https://fonts.googleapis.com/css?family=Libre+Barcode+128+Text, and the attached JavaScript code to calculate the checksum.
var buttonGen = document.getElementById("btnGen");
buttonGen.onclick = function () {
var x = document.getElementById("textIn").value;
var i, j, intWeight, intLength, intWtProd = 0, arrayData = [], fs;
var arraySubst = [ "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê" ];
/*
* Checksum Calculation for Code 128 B
*/
intLength = x.length;
arrayData[0] = 104; // Assume Code 128B, Will revise to support A, C and switching.
intWtProd = 104;
for (j = 0; j < intLength; j += 1) {
arrayData[j + 1] = x.charCodeAt(j) - 32; // Have to convert to Code 128 encoding
intWeight = j + 1; // to generate the checksum
intWtProd += intWeight * arrayData[j + 1]; // Just a weighted sum
}
arrayData[j + 1] = intWtProd % 103; // Modulo 103 on weighted sum
arrayData[j + 2] = 106; // Code 128 Stop character
chr = parseInt(arrayData[j + 1], 10); // Gotta convert from character to a number
if (chr > 94) {
chrString = arraySubst[chr - 95];
} else {
chrString = String.fromCharCode(chr + 32);
}
// Change the font-size style to match the drop down
fs = document.getElementsByTagName("option")[document.getElementById("selList").selectedIndex].value;
document.getElementById("test").style.fontSize = fs + 'px';
document.getElementById("check").innerHTML =
'Checksum = ' + chr + ' or character ' + // Make It Visual
chrString + ', for text = "' + x + '"';
document.getElementById("test").innerHTML =
'Ì' + // Start Code B
x + // The originally typed string
chrString + // The generated checksum
'Î'; // Stop Code
}
td, th {
text-align: center;
padding: 6px;
}
.ss {
font-family: 'Libre Barcode 128 Text', cursive;
font-size: 24px;
}
Font Size:
ÌMaking the Web Beautiful!$Î
This is a demonstration of use of the Libre Barcode 128 Font.
Because the Libre Barcode Code 128 font does not generate checksums, you need this component to produce a scanning barcode.
To use, just enter the text you want to embed in the barcode and press the generate button. Happy barcoding!
By the way, Libre Barcode 128 Font uses the following high ASCII / unicode characters to implement the control codes symbols. (This is essentially adding 100 to the value, in other words 'Ã' is U+00C3 (195) to 'Î' is U+00CE (206).)
Value |
Encoding |
Subst |
95 |
A: US, B: DEL, C: 95 |
à |
96 |
A: FNC 3, B: FNC 3, C: 96 |
Ä |
97 |
A: FNC 2, B: FNC 2, C: 97 |
Å |
98 |
A: Shift B, B: Shift A, C: 98 |
Æ |
99 |
A: Code C, B: Code C, C: 99 |
Ç |
100 |
A: Code B, B: FNC 4, C: Code B |
È |
101 |
A: FNC 4, B: Code A, C: Code A |
É |
102 |
A: FNC 1, B: FNC 1, C: FNC 1 |
Ê |
103 |
Begin Code A |
Ë |
104 |
Begin Code B |
Ì |
105 |
Begin Code C |
Í |
106 |
Stop Code |
Î |
Run code snippetExpand snippet
In order to get a Code 128 barcode to print and scan, a checksum needs to be calculated. This involves calculating a weighted sum of the contents of Lot Number and deriving its remainder of division by 103.