Search code examples
c#barcodezxing.netgs1-128

Generate GS1-128 using ZXing.Net


We use ZXing.Net to generate code 128 barcode and everything works fine.

BarcodeWriter writer = new BarcodeWriter { Format = BarcodeFormat.CODE_128 };
writer.Write("01950123456789031000012317150801").Save("code128.png", ImageFormat.Png);

enter image description here

Recently we have been asked to change the format to GS1-128 and after some research we found this solution using FNC1 (ASCII 29) to write DataMatrix GS1. https://stackoverflow.com/a/43575418/823247

BarcodeWriter writer = new BarcodeWriter { Format = BarcodeFormat.DATA_MATRIX };
writer.Write($"{(char)29}019501234567890310000123{(char)29}17150801").Save("gs1datamatrix.png", ImageFormat.Png);

enter image description here

However, if we change the barcode format to BarcodeFormat.CODE_128, the program will throw exception showing Bad character in input:

BarcodeWriter writer = new BarcodeWriter { Format = BarcodeFormat.CODE_128 };
writer.Write($"{(char)29}019501234567890310000123{(char)29}17150801").Save("gs1code128.png", ImageFormat.Png);

Any advice will be appreciated.


Solution

  • Instead of "(char)29" you have to use the value "(char)0x00F1" as group separator.