Reputation: 622
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);
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);
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.
Upvotes: 3
Views: 6005
Reputation: 857
There is an easier approach to generate GS1-128 barcode via Zxing.Net without manually adding character FNC1 to content.
You should only set the flag GS1Format = true
barcodeWriterSvg.Format = BarcodeFormat.CODE_128;
barcodeWriterSvg.Options.GS1Format = true;
barcodeWriterSvg.Options.Margin = 64;
var svgImage = barcodeWriterSvg.Write(content);
return svgImage.Content;
But the original solution based on manually adding FNC1 character to the beginning of string https://github.com/micjahn/ZXing.Net/wiki/Generating-GS1-DataMatrix-and-GS1-Code128-barcodes
Upvotes: 0
Reputation: 2486
Instead of "(char)29" you have to use the value "(char)0x00F1" as group separator.
Upvotes: 4