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 stringGETCODE128A (stringinputdata) { stringresult =""; intChecksum =103; intj =1; for(intII =0; II < inputdata.length; ii++) { if(Inputdata[ii] >= +) {Checksum+ = (Inputdata[ii]- +) * (ii +1); } Else{checksum+ = (Inputdata[ii] + -) * (ii +1); }} Checksum= checksum%103; if(Checksum < the) {Checksum+= +; } Else{checksum+= -; } result= Convert.tochar (203) + inputdata.tostring () + Convert.tochar (checksum) + Convert.tochar (206); returnresult; }
code128b
Public stringGETCODE128B (stringinputdata) { stringresult =""; intChecksum =104; intj =1; for(intII =0; II < inputdata.length; ii++) { if(Inputdata[ii] >= +) {Checksum+ = (Inputdata[ii]- +) * (ii +1); } Else{checksum+ = (Inputdata[ii] + -) * (ii +1); }} Checksum= checksum%103; if(Checksum < the) {Checksum+= +; } Else{checksum+= -; } result= Convert.tochar (204) + inputdata.tostring () + Convert.tochar (checksum) + Convert.tochar (206); returnresult; }
code128c
Public Static stringGETCODE128C (stringinputdata) { stringresult =""; intChecksum = the; intj =1; for(intII =0; II < inputdata.length; ii++) { if(ii%2==0) {Checksum+ = Convert.ToInt32 (inputdata.substring (II,2)) *J; if(Convert.ToInt32 (inputdata.substring (II,2)) < the) {result+ = Convert.tochar (Convert.ToInt32 (inputdata.substring (ii),2)) + +); } Else{result+ = Convert.tochar (Convert.ToInt32 (inputdata.substring (ii),2)) + -); } J++; } II++; } Checksum= checksum%103; if(Checksum < the) {Checksum+= +; } Else{checksum+= -; } result= Convert.tochar (205) + result + Convert.tochar (checksum) + Convert.tochar (206); returnresult; }
Convert text to code128 barcodes with Code128 fonts