简体   繁体   中英

Crystal Reports barcode Code 128 with C#

I am really confused about printing and reading barcodes. I want to generate Code 128 barecode using C#. Using Crystal Reports I found two ways to this:

  • by adding dll files
  • by using barcode Code 128 font

However I am looking to do this in my own application, not Crystal Reports.

I want to know what the difference between them? Is there any problem by using the font one since it is more simple and do not any add file-ons to my project?

Finally anyone can give me a link to download barcode Code 128 font (FREE)

The thing about Code128 is that you can not just use a font and go for it (like it's the case for CODE39 for example). Why?

  1. You need to add start/stop codes.
  2. There are three subsets, A, B AND C which can be chosen and mixed within a barcode. They differ in the characters they can represent (for example: Subset C can only contain an even number of numbers , subset A can not contain small letters, etc.). You need to know what you want to encode.
  3. You need to calculate a checksum.
  4. Some of the "ASCII codes" for the symbologies are outside the printable area of the normal charsets.

Result: You really need a piece of software to "encode" the barcode.

Example: The software needs to convert

Hello User

into

<STARTB>Hello User<CHECKSUM><STOPCODE>

Or the number

0815

would have to be turned into

<STARTC>(/<CHECKSUM><STOPCODE>

You can, of course, use a ready-made library. However: If you search for a description of Code 128 you will be very easily able to implement it yourself. Usually you'll end up with an image.

I found that this project has really helped me out with barcodes; http://www.codeproject.com/Articles/20823/Barcode-Image-Generation-Library .

It supports a decent amount of encodings and is fairly easy to use

                string value = "12345678";
                TYPE encoding = TYPE.CODE128;

                var barcode = new Barcode(value, encoding);
                barcode.IncludeLabel = true; //We want to display the value below the image.
                Image image = barcode.Encode(encoding, value, 300, 100);
                //Handle the image here...

Although it is not a font it does return an image like this

在此处输入图片说明

which could be printed or handled however you wish.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM