Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To generate a GS1-128 barcode in C# using Barcodelib, follow these steps:

  1. Install the Barcodelib library from NuGet:
Install-Package Barcodelib
  1. Import the Barcodelib namespace:
using BarcodeLib;
  1. Create a new instance of the Barcode class:
Barcode barcode = new Barcode();
  1. Set the BarcodeType property to "GS1-128":
barcode.BarcodeType = BarcodeType.GS1_128;
  1. Set the data to be encoded in the barcode using the Encode method:
string data = "(01)01234567891234(17)180801(21)190123(10)ABC123";
Image barcodeImage = barcode.Encode(BarcodeLib.TYPE.CODE128, data);

In this example, the data is a GS1-128 formatted string. The "(01)" indicates the Global Trade Item Number (GTIN), the "(17)" indicates the expiration date, the "(21)" indicates the serial number, and the "(10)" indicates the batch/lot number.

  1. The barcode is generated as an Image object. You can then save the image to a file or display it in a picture box:
barcodeImage.Save("barcode.png", ImageFormat.Png);