there.are.illegal.characters.for.barcode.128 exception when using CODE128_UCC in itextsharp 5.5.4 .net

1.6k views Asked by At

When attempting to create an GS1-128 barcode I encounter the following exception: there.are.illegal.characters.for.barcode.128.in.1

        iTextSharp.text.pdf.Barcode barcode = null;
        barcode = new Barcode128();
        barcode.CodeType = iTextSharp.text.pdf.Barcode.CODE128_UCC;
        barcode.GenerateChecksum = true;
        barcode.Code = code;
        using (var image = barcode.CreateDrawingImage(Color.Black, Color.White))
2

There are 2 answers

0
AbstractLabs On

After pulling down the source it looks like there might be a bug in the library the code calling into GetRawText. It will pass CodeSet Auto which fails the assertions in in the method. I determined the following to be an acceptable workaround:

        iTextSharp.text.pdf.Barcode barcode = null;
        barcode = new Barcode128();
        barcode.CodeType = iTextSharp.text.pdf.Barcode.CODE128_RAW;
        barcode.GenerateChecksum = true;
        barcode.Code = Barcode128.GetRawText(code, true, Barcode128.Barcode128CodeSet.C);
        using (var image = barcode.CreateDrawingImage(Color.Black, Color.White))
0
pushpendra kataria On

code.Normalize(NormalizationForm.FormKC)

Worked for me. try this.