Generate EAN-2 and EAN-5 Barcodes as Supplement in JavaScript
Overview
Aspose.BarCode for JavaScript via C++ supports the generation of EAN 2 and EAN 5 barcode types as supplements to the following symbologies: EAN 13, EAN 8, Interleaved 2-of-5, ISBN, ISMN, ISSN, Standard 2-of-5, UPC-A, and UPC-E. Supplement barcodes can encode two or five additional digits beyond the main barcode and have their own checksum. These barcodes are used in various industries to encode extra information, such as product details or pricing, although they can also be used for other purposes in production.
Supplement Barcode Settings
The main product information is encoded in the primary barcode, while additional data is added using a supplement barcode. Aspose.BarCode for JavaScript via C++ allows you to use the SupplementData property in the SupplementParameters class, which is part of the Supplement property group. The SupplementData property should be set with either 2 or 5 numerical digits for EAN 2 or EAN 5 supplements, respectively. The barcode type is determined automatically based on the number of digits, and the size of the supplement barcode is calculated based on the main barcode’s parameters.
Below are examples of EAN 13 barcodes with EAN 2 and EAN 5 supplement settings.
Supplement Barcode |
EAN 2 |
EAN 5 |
---|---|---|
The code snippet below demonstrates how to generate supplement barcodes using EAN 2 and EAN 5 symbologies.
// Generate EAN-13 barcodes with different supplements
var gen = new BarCodeInstance.BarcodeGenerator("EAN13", "1234567890128");
gen.Parameters.Barcode.XDimension = "2px";
gen.Parameters.Barcode.Supplement.SupplementSpace = "20px";
// Set EAN-2 supplement
gen.Parameters.Barcode.Supplement.SupplementData = "12";
document.getElementById("img2").src = gen.GenerateBarCodeImage(); // Display barcode image
// Set EAN-5 supplement
gen.Parameters.Barcode.Supplement.SupplementData = "12345";
document.getElementById("img5").src = gen.GenerateBarCodeImage(); // Display barcode image
gen.delete();
Adjust Spacing Between Main and Supplement Barcodes
To set the spacing between the main and supplement barcodes, the SupplementSpace property in the SupplementParameters class can be used.
The barcode examples below show different gap settings between the main and supplement barcodes.
Supplement Spacing |
Set to 20 Pixels |
Set to 40 Pixels |
---|---|---|
The following code snippet demonstrates how to set the spacing between the main and supplement barcodes for the EAN 13 symbology.
// Generate EAN-13 barcode with different supplement space settings
var gen = new BarCodeInstance.BarcodeGenerator("EAN13", "1234567890128");
gen.Parameters.Barcode.XDimension = "2px";
gen.Parameters.Barcode.Supplement.SupplementData = "12345";
// Set supplement space to 20 pixels
gen.Parameters.Barcode.Supplement.SupplementSpace = "20px";
document.getElementById("img").src = gen.GenerateBarCodeImage(); // Display barcode image
// Set supplement space to 40 pixels
gen.Parameters.Barcode.Supplement.SupplementSpace = "40px";
document.getElementById("img").src = gen.GenerateBarCodeImage(); // Display barcode image
gen.delete();