How to generate barcode async API for barcode generator API in JavaScript and PDF.co Web API

Step By Step Tutorial: how to generate barcode async API for barcode generator API in JavaScript

The documentation is designed to help you to implement the features on your side. PDF.co Web API was made to help with barcode generator API in JavaScript. PDF.co Web API is the Rest API that provides set of data extraction functions, tools for documents manipulation, splitting and merging of pdf files. Includes built-in OCR, images recognition, can generate and read barcodes from images, scans and pdf.

The SDK samples like this one below explain how to quickly make your application do barcode generator API in JavaScript with the help of PDF.co Web API. Follow the instruction and copy – paste code for JavaScript into your project’s code editor. Further enhancement of the code will make it more vigorous.

PDF.co Web API – free trial version is on available our website. Also, there are other code samples to help you with your JavaScript application included into trial version.

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

generate_barcode.js
      
var apiKey = ""; function generateBarcode() { // Hide result blocks document.getElementById("errorBlock").style.display = "none"; document.getElementById("resultBlock").style.display = "none"; // Get API Key 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 url += "&async=True"; // Set async api // 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); checkIfJobIsCompleted(result.jobId, result.url); } // 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 checkIfJobIsCompleted(jobId, resultFileUrl) { var url = 'https://api.pdf.co/v1/job/check?jobid=' + jobId; // 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 jobResult = JSON.parse(httpRequest.responseText); if (jobResult.status == "working") { // Check again after 3 seconds setTimeout(function(){ checkIfJobIsCompleted(jobId, resultFileUrl); }, 3000); } else if (jobResult.status == "working") { document.getElementById("resultBlock").style.display = "block"; // show hidden resultBlock document.getElementById("image").setAttribute("src", resultFileUrl); // Set image link to display // Hide loader showLoader(false); } } // 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(); } 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: