Question

First of all, I'm kinda new to the barcode formats and what I do know, I've learned from Wikipedia.

We have some barcodes generated by an existing app that uses the Barcode.4NET library. The barcode is in Code 128A format. The code to generate them is pretty simple, looking something like this:

// Create the barcode
Code128ABarcode c128A = new Code128ABarcode("045746201627080857");

No other parameters are set for it - after setting the data, we just get a GIF version of the barcode back from the library.

I'm working on a new app that is using iTextSharp for PDF generation and I figured that instead of using two libraries, I would use iTextSharp's barcode generation library since it supports Code128 barcodes. It has a few different variations of Code 128, but none of them are "Code 128A".

Here is what the code looks like for it:

Barcode128 code128 = new Barcode128();
code128.CodeType = Barcode.CODE128;
code128.ChecksumText = true;
code128.GenerateChecksum = true;
code128.StartStopText = true;
code128.Code = "045746201627080857";

The image below shows the best I've accomplished so far.

alt text

The image on top is generated by iTextSharp and the one on the bottom is generated by Barcode4Net. Obviously, they aren't the same (and not just in the size and the font - the barcoded data is pretty different).

Is anyone out there familiar enough with iTextSharp's (or iText itself) barcode components or with Code 128A barcodes to tell me how to make the iTextSharp one look exactly like the Barcode.4NET one?

Was it helpful?

Solution

Is it really necessary for them to look exactly the same? The different versions of Code 128 are all capable of encoding numbers, even if the barcodes themselves look completely different; the reader should sort it all out in the end.

I prefer the B variant, because it has the lower case letters in addition to the upper case. You can see a table detailing the differences at http://www.barcodeisland.com/code128.phtml

iTextSharp looks like it is generating variant C, which is the most compact if the text is only decimal digits. It encodes 2 digits in the same amount of space as a single character in the other encodings.

OTHER TIPS

the number should be:

*045746201627080857*

you need to add the asterisk to the start and the end so the Barcode can be readed, you need to check in the component documentation witch one needs this characters.

the scanner needs the leading and the trailing asterisk on this type of BC.

for what I can see in your code, the line

code128.StartStopText = true;

automatically adds it, try to set this property to false, you will end up with the same barcode. In the first code you should use

Code128ABarcode c128A = new Code128ABarcode("*045746201627080857*");

try yourself :)

Edited:

The correct barcode is:

alt text http://www.bcgen.com/demo/linear-dbgs.aspx?D=045746201627080857&S=13&CS=1

from the link below (using ID Automation free service):

http://www.bcgen.com/demo/linear-dbgs.aspx?D=045746201627080857&S=13&CS=1

what you have is:

alt text http://www.bcgen.com/demo/linear-dbgs.aspx?D=045746201627080857&S=13&CS=3

and this is Code128C instead of Code128A as you can check the link (I changed the barcode properties to Code128C)

http://www.bcgen.com/demo/linear-dbgs.aspx?D=045746201627080857&S=13&CS=3

While I think balexandre has the generators mixed up, his advice is good.

Evidently Barcode.4NET is correctly generating the Code 128A barcode that I am trying to emulate.

iTextSharp is generating a Code 128C barcode which, according to Mark Ransom, should be OK except for the users and customer will probably look at it and say "It's too short and should look like the other ones!"

So, great advice, but I'm still back to "How do I generate a Code 128A barcode with iTextSharp?"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top