How to Generate an EAN-13 Barcode in JavaScript
--
While the UPC-A barcode is the standard across North America, the EAN-13 barcode is the most commonly used in Europe. This version contains 13 digits, and similar to the UPC-A format, it can be used internationally. In this brief tutorial, we will demonstrate how to automatically generate an EAN-13 barcode image using an API in JavaScript.
Our first step is to install the jQuery library:
bower install jquery
Next, we can call the function with the following code:
var settings = {
"url": "https://api.cloudmersive.com/barcode/generate/ean-13",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"Apikey": "YOUR-API-KEY-HERE"
},
"data": {
"0": "<",
"1": "s",
"2": "t",
"3": "r",
"4": "i",
"5": "n",
"6": "g",
"7": ">"
}
};$.ajax(settings).done(function (response) {
console.log(response);
});
This will return a PNG file of the barcode that is downloadable and ready for use!