Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To create a GS1-128 barcode using ZXing.Net, follow these steps:

  1. Install ZXing.Net package using NuGet Package Manager.

  2. Import the necessary namespaces:

using ZXing;
using ZXing.Common;
using ZXing.OneD;
  1. Create an instance of the BarcodeWriter class and set the encoding parameters:
var writer = new BarcodeWriter
{
     Format = BarcodeFormat.CODE_128,
     Options = new EncodingOptions
     {
         Width = 400,
         Height = 100,
         Margin = 10,
         PureBarcode = true,
     },
};
  1. Generate the barcode image by passing the data to be encoded as a string:
var barcode = writer.Write("(10)123456(17)200101(30)200101(21)A12345");
  1. Save or display the generated barcode image:
barcode.Save("gs1-128.png", ImageFormat.Png);
pictureBox1.Image = barcode;

The example above generates a GS1-128 barcode with the data "(10)123456(17)200101(30)200101(21)A12345". This data contains four elements: the Global Trade Item Number (GTIN), the expiration date, the production date, and a serial number. GS1-128 barcodes can include many other data elements depending on the needs of the barcode user.