Ask Your Question
3

How can Barcodelib be used to generate a GS1-128 barcode in C#?

asked 2023-07-19 19:39:32 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-07-19 19:49:01 +0000

djk gravatar image

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);
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-19 19:39:32 +0000

Seen: 14 times

Last updated: Jul 19 '23