EAN-13, based upon the UPC-A standard, is used world-wide for marking retail goods. The 13-digit EAN-13 number consists of four components:
- Country code - 2 or 3 digits
- Manufacturer Code - 5 to 7 digits
- Product Code - 3 to 5 digits
- Check digit - last digit
The following code snippets demonstrate how to create EAN-13 barcode image using Spire.Barcode in C#.
Step 1: Create a BarcodeSettings instance.
BarcodeSettings settings = new BarcodeSettings();
Step 2: Set the barcode type as EAN13.
settings.Type = BarCodeType.EAN13;
Step 3: Set the data to encode.
settings.Data = "123456789012";
Step 4: Calculate checksum and add the check digit to barcode.
settings.UseChecksum = CheckSumMode.ForceEnable;
Step 5: Display barcode's text on bottom and centrally align the text.
settings.ShowTextOnBottom = true; settings.TextAlignment = StringAlignment.Center;
Step 6: Generate barcode image based on the settings and save it in .png format.
BarCodeGenerator generator = new BarCodeGenerator(settings); Image image = generator.GenerateImage(); image.Save("EAN-13.png", System.Drawing.Imaging.ImageFormat.Png);
Output:
Full Code:
using Spire.Barcode; using System.Drawing; namespace EAN-13 { class Program { static void Main(string[] args) { BarcodeSettings settings = new BarcodeSettings(); settings.Type = BarCodeType.EAN13; settings.Data = "123456789012"; settings.UseChecksum = CheckSumMode.ForceEnable; settings.ShowTextOnBottom = true; settings.TextAlignment = StringAlignment.Center; BarCodeGenerator generator = new BarCodeGenerator(settings); Image image = generator.GenerateImage(); image.Save("EAN-13.png", System.Drawing.Imaging.ImageFormat.Png); } } }