How to Generate EAN-13 and EAN-8 Barcodes for Retail Products in .NET
What Are EAN-13 and EAN-8 Barcodes?
EAN-13 and EAN-8 are the global standards for retail product barcodes. EAN-13 encodes 13 digits and is used on virtually all consumer goods worldwide; EAN-8 is a compact, 8-digit version for small packages and limited-label space. Both formats enable fast, error-free checkout, inventory, and supply chain management.
Quick Start (Minimal Example)
using Aspose.BarCode.Generation;
var generator = new BarcodeGenerator(EncodeTypes.EAN13, "590123412345");
generator.Save("product-ean13.png", BarCodeImageFormat.Png);
Table of Contents
- Introduction
- What Are EAN-13 and EAN-8 Barcodes?
- Quick Start (Minimal Example)
- Prerequisites
- Step-by-Step Implementation
- Customizing Barcode Appearance
- Supported Output Formats
- Troubleshooting & Common Issues
- FAQs
- Use Cases and Applications
- Best Practices
- Related Articles & Internal Links
- Conclusion
Introduction
This article demonstrates how to generate EAN-13 and EAN-8 barcodes for retail products using Aspose.BarCode for .NET. Includes complete C# code, customization tips, and answers to real-world retail integration questions.
Prerequisites
- Visual Studio 2019 or later
- .NET 6.0+ or .NET Framework 4.6.2+
- Aspose.BarCode for .NET installed (NuGet)
- Basic C# knowledge
PM> Install-Package Aspose.BarCode
Step-by-Step Implementation
EAN-13 Example:
using Aspose.BarCode.Generation;
BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.EAN13, "590123412345"); // 12 digits + auto-checksum
gen.Save("product-ean13.png", BarCodeImageFormat.Png);
EAN-8 Example:
BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.EAN8, "9638507"); // 7 digits + auto-checksum
gen.Save("product-ean8.png", BarCodeImageFormat.Png);
Customizing Barcode Appearance
- Bar Height/Width:
csgen.Parameters.Barcode.BarHeight.Pixels = 80; gen.Parameters.Barcode.XDimension.Pixels = 2;
- Color/Background:
csgen.Parameters.Barcode.BarColor = Color.DarkBlue; gen.Parameters.Barcode.BackColor = Color.White;
- Caption:
csgen.Parameters.CaptionBelow\.Visible = true;
- Rotation (for packaging):
csgen.Parameters.RotationAngle = 90;
Supported Output Formats
- PNG, JPEG, BMP – Standard image formats for print or web
- TIFF – For high-resolution or batch printing
- SVG, EMF – For scalable vector artwork
Troubleshooting & Common Issues
Barcode not scanning?
- Ensure the code is all digits (no letters/spaces), correct length, and not too small on print/export
Wrong or missing checksum?
- Aspose.BarCode adds checksums automatically—just supply 12 or 7 digits
Label doesn’t fit?
- Use EAN-8 for smaller packaging; reduce bar height/XDimension
FAQs
Q: Can I generate barcodes for multiple products in a batch? A: Yes. Loop through your product list and generate/save each barcode image programmatically.
Q: Can I use color barcodes? A: For maximum scanner compatibility, stick to dark bars on a light background; use colors with caution.
Use Cases and Applications
- Retail and grocery checkout
- Inventory and stockroom labeling
- POS receipts and shelf tags
- E-commerce product images
Best Practices: Quick Reference Table
Tip | Do | Don’t |
---|---|---|
Code Length | EAN-13: 12 digits, EAN-8: 7 | Add extra/short digits |
Bar Color | Black/DarkBlue on White | Red/Yellow bars |
Caption | Show below for readability | Overlap with bars |
Output Format | Use PNG/SVG for crisp output | Low-res JPG for printing |
Conclusion
EAN-13 and EAN-8 barcodes are the gold standard for retail and inventory worldwide. Aspose.BarCode for .NET makes it simple to generate compliant, high-quality barcodes for every use case. See the Aspose.BarCode API Reference for more details and advanced scenarios.