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 quick and easy way to add a required functionality into 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, images recognition, pdf splitting and pdf splitting. 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 implimentation of this functionality, please copy and paste code below into your app using 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.

Trial version of ByteScout is available for free download from our website. This and other source code samples for JavaScript and other programming languages are available.

Try PDF.co Web API today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)

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("GET", 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"; } }

Try PDF.co Web API today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)

VIDEO

ON-PREMISE VERSION INFORMATION

Get 60 Day Free Trial or Visit PDF.co Web API Home Page

Explore PDF.co Web API Documentation

Get PDF.co Web API Free Training

WEB API

Get Your Free API Key

Explore Web API Documentation

Related Samples: