How to Generate Barcode for Barcode Generator API in JavaScript and PDF.co Web API
See How to Generate Barcode to Have Barcode Generator API in JavaScript
Source code documentation samples provide a quick and easy way to add the required functionality to your application. PDF.co Web API helps with barcode generator API in JavaScript. PDF.co Web API is the flexible Web API that includes full set of functions from e-signature requests to data extraction, OCR, image recognition, PDF splitting, and PDF merging. Can also generate barcodes and read barcodes from images, scans, and PDF.
You will save a lot of time on writing and testing code as you may just take the code below and use it in your application. For the implementation of this functionality, please copy and paste the code below into your app using the code editor. Then compile and run your app. This basic programming language sample code for JavaScript will do the whole work for you in implementing barcode generator API in your app.
On-demand (REST Web API) version:
Web API (on-demand version)
On-premise offline SDK for Windows:
60 Day Free Trial (on-premise)
generate_barcode.js
function generateBarcode() { // Hide result blocks document.getElementById("errorBlock").style.display = "none"; document.getElementById("resultBlock").style.display = "none"; // Get API Key var apiKey = document.getElementById("apiKey").value.trim(); if (apiKey == "") { alert("API Key should not be empty."); return false; } // Get barcode type var barcodeType=document.getElementById("barcodeType").value; // Get barcode value var inputValue = document.getElementById("inputValue").value.trim(); if (inputValue == null || inputValue == "") { alert("Barcode Value should not be empty."); return false; } //show loader showLoader(true); // Prepare URL var url = "https://api.pdf.co/v1/barcode/generate?name=barcode.png"; url += "&type=" + barcodeType; // Set barcode type (symbology) url += "&value=" + inputValue; // Set barcode value // Prepare request var httpRequest = new XMLHttpRequest(); httpRequest.open("POST", url, true); httpRequest.setRequestHeader("x-api-key", apiKey); // set API Key // Asynchronous response handler httpRequest.onreadystatechange = function() { if (httpRequest.readyState == 4) { // If OK if (httpRequest.status == 200) { var result = JSON.parse(httpRequest.responseText); if (result.error == false) { document.getElementById("resultBlock").style.display = "block"; // show hidden resultBlock document.getElementById("image").setAttribute("src", result.url); // Set image link to display } else { document.getElementById("errorBlock").style.display = "block"; // show hidden errorBlock document.getElementById("error").innerHTML = result.message; } } // Else display error else { document.getElementById("errorBlock").style.display = "block"; // show hidden errorBlock document.getElementById("error").innerHTML = "Request failed. Please check you use the correct API key."; } // Hide loader showLoader(false); } } // Send request httpRequest.send(); return true; } function showLoader(isDisplay){ var loader = document.getElementById("loader"); if(isDisplay){ loader.style.display = ""; } else{ loader.style.display="none"; } }
VIDEO
ON-PREMISE OFFLINE SDK
See also:
ON-DEMAND REST WEB API
Get Your API Key
See also:
PDF-co-Web-API-JavaScript-Generate-Barcode.pdf