I am going to share very simple java code to generate barcode and read barcode from an image in cloud and I am using Aspose’s cloud library for this known as Aspose.Barcode for Cloud API.

I am sharing two code snippets one is for generating barcode by using REST API in java and second one is for generating barcode by using Java SDK

Generate Barcodes using Java REST

First you need to set any text and supported type in the following URI to create a new barcode.

http://api.aspose.com/v1.1/barcode/generate?text=Text for new barcode image&type=QR

After building the URI, you need to go through the following steps:

1. Set App SID and App Key and sign the URI.
See section 1 of the following code and Sign URI method for more details.
2. Send a GET request to Aspose for Cloud service.
See section 2 of the following code and ProcessCommand method for more details.
3. Save output barcode image to disk.
See section 3 of the following code and SaveStreamToFile method for more details.

Below is the code to create a new barcode.

/**** Section 1 ****/ 
//Build URI to generate barcode 
//Type:  Codabar, Code11, Code128 and Code39Extended etc. 
//Format:  PNG, JPEG and JPG etc. 

String strURI = "http://api.aspose.com/v1.1/barcode/generate?text=Barcode Text Here&type=QR&format=png"; 

//Sign URI

String signedURI = Utils.Sign(strURI);

/**** End Section 1 ****/

/**** Section 2 ****/

InputStreamresponseStream=  Utils.ProcessCommand(signedURI, "GET");

/**** End Section 2 ****/

/**** Section 3 ****/

Folder.SaveStreamToFile("Barcode1.png", responseStream);

/**** End Section 3 ****/


Generate Barcodes using Java SDK

If you want to use Java SDK to create a new barcode, you can download the following SDK from Aspose for Cloud SDK for Java. In order to use the Java SDK, user need to perform following steps:


1. Set base product URI, App SID and App Key.
See section 1 of the following code.
2. Create object of the BarCodeBuilder class and call the Save method.
See section 2 of the following code.

Below is the code that creates a new barcode.

/**** Section 1 ****/


/**** End Section 1 ****/

/**** Section 2 ****/

//Create an instance of BarCodeBuilder class
com.aspose.cloud.barcode.BarCodeBuilder builder = newcom.aspose.cloud.barcode.BarCodeBuilder("Pdf417
barcode generated by Aspose.BarCode for Cloud",
// Call Save() method to save the barcode to local disk
builder.Save(com.aspose.cloud.barcode.SaveLocation.Local, "Barcode1.png",

/**** End Section 2 ****/
I hope this code will help you understand how to create barcode API in cloud.