ConvertBarcodeSplit - NodeJS

This tutorial shows how to convert and split out barcodes from files using the LEADTOOLS Cloud Services in a NodeJS application.

Summary This tutorial covers how to make ConvertBarcodeSplit requests and process the results using the LEADTOOLS Cloud Services in a NodeJS application.
Completion Time 30 minutes
Project Download tutorial project (125 KB)
Platform LEADTOOLS Cloud Services API
IDE Visual Studio 2019
Language NodeJS
Development License Download LEADTOOLS
Try it in another language

Required Knowledge

Be sure to review the following sites for information about LEADTOOLS Cloud Services API.

Application ID and Password

Create an Account with LEADTOOLS Hosted Cloud Services to obtain both Application ID and Password strings.

Service Plans

LEADTOOLS Service Plan offerings:

Service Plan Description
Free Trial Free Evaluation
Page Packages Prepaid Page Packs
Subscriptions Prepaid Monthly Processed Pages

To further explore the offerings, refer to the LEADTOOLS Hosted Cloud Services page.

To obtain the necessary Application ID and Application Password, refer to Create an Account and Application with the LEADTOOLS Hosted Cloud Services.

Add the ConvertBarcodeSplit Code

With the project created and the package added, coding can begin.

In the Solution Explorer, open server.js. Add the following variables at the top.

//Simple script to make and process the results of a ConvertBarcodeSplit request to the LEADTOOLS CloudServices. 
const axios = require("axios"); 
const FormatsEnum = { 
  png: 1, 
  jpeg: 2, 
  tiff: 3, 
  pdf: 4, 
  pdfa: 5, 
  pdfImage: 6, 
  pdfImageOverText: 7, 
  pdfaImageOverText: 8, 
  docx: 9, 
  docxFramed: 10, 
  rtf: 11, 
  rtfFramed: 12, 
  txt: 13, 
  txtFramed: 14, 
const servicesUrl = ""; 
//The first page in the file to mark for processing 
const firstPage = 1; 
//Sending a value of -1 will indicate to the services that the rest of the pages in the file should be processed. 
const lastPage = -1; 
//Enum corresponding to the output format for the file. For the purposes of this script, we will be converting to tif. 
const fileFormat = FormatsEnum.tiff; 
const splitOptions = 1; //discard 
//We will be uploading the file via a URL.  Files can also be passed by adding a PostFile to the request.  Only 1 file will be accepted per request. 
//The services will use the following priority when determining what a request is trying to do GUID > URL > Request Body Content 
const fileURL = 
const conversionUrl = 
  servicesUrl + 
  "Conversion/ConvertBarcodeSplit?firstPage=" + 
  firstPage + 
  "&lastPage=" + 
  lastPage + 
  "&fileurl=" + 
  fileURL + 
  "&format=" + 
  fileFormat + 
  "&splitOptions=" + 

Add an call to process the ConvertBarcodeSplit request as well as the conversionCallback function to capture the GUID and provide it to the next section. This sends an ConvertBarcodeSplit request to the LEADTOOLS Cloud Services API, if successful, a unique identifier (GUID) will be returned and then a query using this GUID will be made.

  .post(conversionUrl, {}, getRequestOptions(conversionUrl)) 
  .then((res) => { 
    conversionCallback(res.error, res,; 
  .catch((err) => { 
//If uploading a file as multi-part content: 
/*const conversionUrl = servicesUrl + 'Conversion/ConvertBarcodeSplit?firstPage=' + firstPage + '&lastPage=' + lastPage + '&format=' + fileFormat; 
const form = new FormData(); 
form.append("file", fs.createReadStream('path\to\inputFile'));, form, getRequestOptions(conversionUrl)).then((res) => { 
    conversionCallback(res.error, res,; 
}).catch ((err) => { 
function conversionCallback(error, response, body) { 
  if (!error && response.status === 200) { 
    const guid = body; 
    console.log("Unique ID returned by the Services: " + guid); 

Next, create an async function called queryServices(guid) that utilizes the GUID provided by ConvertBarcodeSplit request. If successful the response body will contain all the request data in JSON format.

async function queryServices(guid) { 
  //Function to query the status of a request.  If the request has not yet finished, this function will recursively call itself until the file has finished. 
  const queryUrl = servicesUrl + "Query?id=" + guid; 
  await axios 
    .post(queryUrl, {}, getRequestOptions(queryUrl)) 
    .then((res) => { 
      const results =; 
      if ( 
        !res.error && 
        results["FileStatus"] !== 100 && 
        results["FileStatus"] !== 123 
      ) { 
        console.log("File finished processing with return code: " + res.status); 
        if (results["FileStatus"] !== 200) { 
        console.log("Results: \n"); 
      } else { 
        //The file has not yet finished processing. 
        return new Promise((resolve) => { 
          setTimeout(() => { 
            //Sleep for 5 seconds before trying again 
            resolve(queryServices(guid)); //Call the method again. 
          }, 5000); 
    .catch((err) => { 

Then, create the function parseJson(jsonObject) to process the returned JSON data.

function parseJson(jsonObject) { 
  //Function to decode the JSON object that was returned by the LEADTOOLS CloudServices. 
  for (let i = 0; i < jsonObject.length; i++) { 
    let currentRequest = jsonObject[i]; 
    console.log("Service Type: " + currentRequest["ServiceType"]); 
    if (currentRequest["ServiceType"] === "Conversion") { 
      console.log("Urls: "); 
      currentRequest["data"]["Urls"].forEach((url) => { 

Finally, create the function getRequestOptions(url) to provide header and authorization to the connections in order to request the GUID and JSON data through. Where it states Replace with Application ID and Replace with Application Password be sure to place your Application ID and Password accordingly.

function getRequestOptions(url) { 
  const appId = "Replace with Application ID"; 
  const password = "Replace with Application Password"; 
  const token = Buffer.from(`${appId}:${password}`, "utf8").toString("base64"); 
  //Function to generate and return HTTP request  options. 
  const requestOptions = { 
    url: url, 
    data: {}, 
    //If uploading a file as multi-part content, remove the Content-Length header. 
    headers: { 
      "Content-Length": 0, 
      Authorization: `Basic ${token}`, 
  return requestOptions; 

Run the Project

Run the project by pressing Ctrl + F5, or by selecting Debug -> Start Without Debugging.

If the steps were followed correctly, the console appears and the application displays the parsed check information from the returned JSON data.

Convert Barcode Split Results


This tutorial showed how to convert and split out barcodes via the LEADTOOLS Cloud Services API.

See Also

Help Version 22.0.2024.3.20
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.