ESC-POS-USB-NET icon indicating copy to clipboard operation
ESC-POS-USB-NET copied to clipboard

Code128 Barcode is not rendering correctly

Open jchathu opened this issue 4 years ago • 3 comments

If we print the code 128 barcode as same as using this method printer.Code128("123456789"); It will print wrong barcode. It will print something like this "495051525354555657" after scanning the printed barcode

Is there anyway to decode this or how can we correct his for Code128 barcodes?

jchathu avatar Sep 10 '21 17:09 jchathu

I just extracted this from here and it works for me

    private byte[] BarcodeBytes(string barcode)
        {
            byte type = 0x49; //CODE128
            byte gs = 0x1D;
            byte printBarcode = 0x6B; 
            byte code = 0x42; //CODE_B

            barcode = barcode.Replace("{", "{{");
            barcode = $"{(char)0x7B}{(char)code}" + barcode;

            var command = new List<byte> { gs, printBarcode, (byte)type, (byte)barcode.Length };
            command.AddRange(barcode.ToCharArray().Select(x => (byte)x));
            return command.ToArray();
        }

Use it with

var printer = new USBPrinter.Printer("printer-name", "utf-8");
printer.Append(BarcodeBytes("123456789"));

iformas avatar Sep 24 '21 13:09 iformas

Hi, I Revie this bug, the problem is the Font Code. Currently is 'C' change the font to 'A' or 'B' 0x42 . fix in the class BarCode.cs I Hope this post can help you.
0x42

PabloGallegosH avatar Oct 23 '22 00:10 PabloGallegosH

Hi, I have created PR #70 that addressing this issue and fix it (and add more config too 😄 ), also there is PR #38 regarding this too.

saper-2 avatar Mar 30 '24 17:03 saper-2