function print_html_barcode(
content,
height,
insertCheckDigit,
printContent,
fontPointSize,
thinBarWidth,
barWidthRatio){
content = content.toUpperCase();
if (isNaN(thinBarWidth)) thinBarWidth = 1;
// if (isNaN(barWidthRatio)) barWidthRatio = 3; was the original width
if (isNaN(barWidthRatio)) barWidthRatio = 2;
var thin = thinBarWidth;
var thick = thinBarWidth*barWidthRatio;
var last = thick*0.66;
var whiteImageURL = 'http://www.johnstones.com/uploads/scripts/white.gif';
var blackImageURL = 'http://www.johnstones.com/uploads/scripts/black.gif';
var thinWhiteBar = "<img src='"+whiteImageURL+"' height='"+height+"' width='"+thin+"'>";
var thinBlackBar = "<img src='"+blackImageURL+"' height='"+height+"' width='"+thin+"'>";
var thickWhiteBar = "<img src='"+whiteImageURL+"' height='"+height+"' width='"+thick+"'>";
var thickBlackBar = "<img src='"+blackImageURL+"' height='"+height+"' width='"+thick+"'>";
var lastBar = "<img src='"+whiteImageURL+"' height='"+height+"' width='"+last+"'>";
// this is the definition array for what bar
// combinations correspond to what characters.
// definition is as follows:
// 0 = thin white (blank) bar
// 1 = thin black bar
// 2 = thick white (blank) bar
// 3 = thick black bar
// the 10th digit is for calculating the check digit
// so, the letter A is:
// [3,0,1,0,1,2,1,0,3,10]
// which means:
// thick black bar
// thin white
// thin black
// thin white
// thin black
// thick white
// thin black
// thin white
// thick black
// and the check digit calculation value is 10
var codes = {
'0' : [1,0,1,2,3,0,3,0,1,0],
'1' : [3,0,1,2,1,0,1,0,3,1],
'2' : [1,0,3,2,1,0,1,0,3,2],
'3' : [3,0,3,2,1,0,1,0,1,3],
'4' : [1,0,1,2,3,0,1,0,3,4],
'5' : [3,0,1,2,3,0,1,0,1,5],
'6' : [1,0,3,2,3,0,1,0,1,6],
'7' : [1,0,1,2,1,0,3,0,3,7],
'8' : [3,0,1,2,1,0,3,0,1,8],
'9' : [1,0,3,2,1,0,3,0,1,9],
'A' : [3,0,1,0,1,2,1,0,3,10], // <-- used in the example above
'B' : [1,0,3,0,1,2,1,0,3,11],
'C' : [3,0,3,0,1,2,1,0,1,12],
'D' : [1,0,1,0,3,2,1,0,3,13],
'E' : [3,0,1,0,3,2,1,0,1,14],
'F' : [1,0,3,0,3,2,1,0,1,15],
'G' : [1,0,1,0,1,2,3,0,3,16],
'H' : [3,0,1,0,1,2,3,0,1,17],
'I' : [1,0,3,0,1,2,3,0,1,18],
'J' : [1,0,1,0,3,2,3,0,1,19],
'K' : [3,0,1,0,1,0,1,2,3,20],
'L' : [1,0,3,0,1,0,1,2,3,21],
'M' : [3,0,3,0,1,0,1,2,1,22],
'N' : [1,0,1,0,3,0,1,2,3,23],
'O' : [3,0,1,0,3,0,1,2,1,24],
'P' : [1,0,3,0,3,0,1,2,1,25],
'Q' : [1,0,1,0,1,0,3,2,3,26],
'R' : [3,0,1,0,1,0,3,2,1,27],
'S' : [1,0,3,0,1,0,3,2,1,28],
'T' : [1,0,1,0,3,0,3,2,1,29],
'U' : [3,2,1,0,1,0,1,0,3,30],
'V' : [1,2,3,0,1,0,1,0,3,31],
'W' : [3,2,3,0,1,0,1,0,1,32],
'X' : [1,2,1,0,3,0,1,0,3,33],
'Y' : [3,2,1,0,3,0,1,0,1,34],
'Z' : [1,2,3,0,3,0,1,0,1,35],
'-' : [1,2,1,0,1,0,3,0,3,36],
'.' : [3,2,1,0,1,0,3,0,1,37],
' ' : [1,2,3,0,1,0,3,0,1,38],
'*' : [1,2,1,0,3,0,3,0,1,39],
'$' : [1,2,1,2,1,2,1,0,1,40],
'/' : [1,2,1,2,1,0,1,2,1,41],
'+' : [1,2,1,0,1,2,1,2,1,42],
'%' : [1,0,1,2,1,2,1,2,1,43]
};
var tw = 0;
var sum = 0;
for (var ee=0; ee<content.length; ee++){
var tcodes = codes[content.charAt(ee)];
if (typeof tcodes!='undefined'){
sum += tcodes[9];
}
}
if (insertCheckDigit){
var checksum = sum%43;
for (x in codes){
if (codes[x][9]==checksum){
content = content+x;
}
}
}
content = '*'+content+'*';
var htmlout = "<"+"table border='0' cellpadding='1' cellspacing='1'>";
htmlout += "<"+"tr><"+"td align='center'><nobr>";
for (var i=0; i<content.length; i++){
tcodes = codes[content.charAt(i)];
if (typeof tcodes!='undefined'){
for (var xi=0; xi<9; xi++){
switch (tcodes[xi]){
case 0:
htmlout += thinWhiteBar;
break;
case 1:
htmlout += thinBlackBar;
break;
case 2:
htmlout += thickWhiteBar;
break;
case 3:
htmlout += thickBlackBar;
break;
}
}
}
htmlout += lastBar;
}
htmlout += "</nobr><"+"/td><"+"/tr>";
if (printContent){
htmlout += "<"+"tr><"+"td align='center' style='font-size: "+fontPointSize+"pt;'>";
htmlout += "<nobr>"+content+"</nobr><"+"/td><"+"/tr>";
}
htmlout += "<"+"/table>";
return htmlout;
}