Recently in the warehousing project, many print files contain barcodes, which have been converted directly to 39 yards using the C39p24dhtt font, but have recently been asked to use a barcode in code128 encoding format. The first thought of the method is to download a code128 font, think immediately after the hands, the results are greatly disappointing, no scanner can identify, no way, can only think of other ways.
Immediately think of is to ask Niang, most of the practice is to convert characters to code128 encoding, and then draw the corresponding bar code, this method is the best, the client does not need to install any related fonts, but the approach is somewhat complicated. Finally found a simple way, but the premise is that the user installed the Code128 font, the following is the specific implementation code for those who need to refer to.
code128a
public string getcode128a (string inputdata) { string result = ""; int checksum = 103; int j = 1; for (int II = 0; II < inputdata.length; ii++) { if (Inputdata[ii] >=) { checksum + = (inputdata[ii ]-(+) * (ii + 1); } else { checksum + = (Inputdata[ii] + +) * (ii + 1);} } Checksum = checksum% 103; if (Checksum <) { checksum + = +; } else { checksum + =; } result = Convert.tochar (203) + inputdata.tostring () + Convert.tochar (checksum) + Convert.tochar (206); return result; }
code128b
public string getcode128b (string inputdata) { string result = ""; int checksum = 104; int j = 1; for (int II = 0; II < inputdata.length; ii++) { if (Inputdata[ii] >=) { checksum + = (inputdata[ii ]-(+) * (ii + 1); } else { checksum + = (Inputdata[ii] + +) * (ii + 1);} } Checksum = checksum% 103; if (Checksum <) { checksum + = +; } else { checksum + =; } result = Convert.tochar (204) + inputdata.tostring () + Convert.tochar (checksum) + Convert.tochar (206); return result; }
code128c
public static string getcode128c (String inputdata) {string result = ""; int checksum = 105; int j = 1; for (int II = 0; II < inputdata.length; ii++) {if (ii 2 = = 0) { Checksum + = Convert.ToInt32 (inputdata.substring (ii, 2)) * J; if (Convert.ToInt32 (Inputdata.substring (ii, 2)) <) {result + = Convert.toc Har (Convert.ToInt32 (inputdata.substring (ii, 2)) + 32); } else {result + = Convert.tochar (Convert.ToInt32 (INPUTDATA.S Ubstring (ii, 2)) + 100); } j + +; } ii++; } checksum = checksum% 103; if (Checksum <) {checksum + = 32; } else {checksum + = 100; } result = Convert.tochar (205) + result + Convert.tochar (checksum) + Convert.tochar (206); return result; }
Convert text to code128 barcodes with Code128 fonts