Convert text to code128 barcodes with Code128 fonts

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.