This project has moved. For the latest updates, please go here.

Writing GS1-128 Barcode: FNC1 issue

Nov 1, 2013 at 2:26 AM
I am trying to create GS1-128 barcodes using Can I write the non-readable FNC1, ASCII code <GS> (ASCII 29)?

I am getting an error when I try:

System.ArgumentException was unhandled by user code
Message=Bad character in input: 
   at ZXing.OneD.Code128Writer.encode(String contents) in C:\ZXing.Net.Build.\Source\lib\oned\Code128Writer.cs:line 90
   at ZXing.OneD.OneDimensionalCodeWriter.encode(String contents, BarcodeFormat format, Int32 width, Int32 height, IDictionary`2 hints) in C:\ZXing.Net.Build.\Source\lib\oned\OneDimensionalCodeWriter.cs:line 79
   at ZXing.OneD.Code128Writer.encode(String contents, BarcodeFormat format, Int32 width, Int32 height, IDictionary`2 hints) in C:\ZXing.Net.Build.\Source\lib\oned\Code128Writer.cs:line 64
   at ZXing.MultiFormatWriter.encode(String contents, BarcodeFormat format, Int32 width, Int32 height, IDictionary`2 hints) in C:\ZXing.Net.Build.\Source\lib\MultiFormatWriter.cs:line 79
   at ZXing.BarcodeWriterGeneric`1.Encode(String contents) in C:\ZXing.Net.Build.\Source\lib\BarcodeWriterGeneric.cs:line 74
   at ZXing.BarcodeWriterGeneric`1.Write(String contents) in C:\ZXing.Net.Build.\Source\lib\BarcodeWriterGeneric.cs:line 91
   at qrstMockup.dynamicqrcode.Page_Load(Object sender, EventArgs e) in C:\Users\Visual Studio 2010\Projects\qrstMockup\qrstMockup\dynamicqrcode.aspx.cs:line 40
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Nov 1, 2013 at 12:46 PM
Please use the following character as FNC-1 symbol in your input string: '\u00f1'
Nov 1, 2013 at 1:20 PM
Hi micjahn,

Thanks for your response!

The barcode is drawing nicely but label below the barcode shows a tilde-n. I also tried using a function to encode the string in ASCII 128 but then I get a "eq" instead of the round brackets.

Should I not use the label and write the human-readable text myself?

Here is the code I am using:
TextBox1.Text = "10764141234621"
TextBox2.Text = "B022B1CF"
string v = '\u00f1' + "01" + TextBox1.Text + '\u00f1' + "10" + TextBox2.Text;
ZXing.BarcodeWriter BW = new ZXing.BarcodeWriter();
BW.Format = ZXing.BarcodeFormat.CODE_128;
BW.Options.Height = 160;
BW.Options.Width = 240;
System.Drawing.Bitmap bitmap = BW.Write(value);
Nov 1, 2013 at 1:36 PM
Yes, you have to write the text yourself.
You have two ways to do so.
First, you can use the PureBarcode option for disabling the text
new ZXing.BarcodeWriter {Options = new EncodingOptions {PureBarcode = true}};
Then you can write the text yourself under the image.

Alternativly you can write your own barcode renderer class which generates the brackets in the output text.
Take a look at the classes
If you have your own renderer you can use it with the BarcodeWriter class:
new ZXing.BarcodeWriter { Renderer = new YourCustomBitmapRenderer() };
Nov 1, 2013 at 2:45 PM
Great, thanks a lot!

Being a very "behaved" application I think it is easier to write the Text myself.

Have a great weekend!