• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Read & Recognize Barcode from External Image URL Using REST API

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This technical tip allows developers to read barcode from external image URL using Saaspose.BarCode REST API in your Java applications. Some important steps for performing this task is to build URI for reading barcode, sending the request to Saaspose server, parsing and Deserializes the JSON to an object and display the value and type of all the recognized barcodes.

Sample Code for Reading Barcode from external image URL

//build URI to read barcode
//type: Codabar, Code11, Code128 and Code39Extended etc.
String strURI = "http://api.saaspose.com/v1.0/barcode/recognize?type=QR&url=http://upload.wikimedia.org/wikipedia/commons/c/ce/WikiQRCode.png";
// Send the request to Saaspose server
InputStream responseStream = ProcessCommand(Sign(strURI), "POST");
// Read the response
String strJSON = StreamToString(responseStream);
//Parse and Deserializes the JSON to a object.
RecognitionResponse barcodeRecognitionResponse = gson.fromJson(strJSON,RecognitionResponse.class);
List<RecognizedBarCode> barcodes = barcodeRecognitionResponse.getBarcodes();

// Display the value and type of all the recognized barcodes
for (RecognizedBarCode barcode : barcodes)
{
System.out.println("Codetext: " + barcode.BarcodeValue() + "\nType: " + barcode.getBarcodeType());
}

\\Here is the RecognitionResponse class
public class RecognitionResponse extends BaseResponse
{
private List<RecognizedBarCode> Barcodes ;
public List<RecognizedBarCode> getBarcodes(){return Barcodes;}
}

\\Here is the RecognizedBarCode class
public class RecognizedBarCode
{
private String BarcodeType ;
private String BarcodeValue;
public String getBarcodeType(){return BarcodeType;}
public String BarcodeValue(){return BarcodeValue;}
}

\\Here is the BaseResponse class
public class BaseResponse
{
public BaseResponse() { }
private String Code;
private String Status;
public String getCode(){return Code;}
public String getStatus(){return Status;}
public void setCode(String temCode){ Code=temCode;}
public void setStatus(String temStatus){ Status=temStatus;}
}

Overview: Saaspose.Barcode

Saaspose.Barcode is a cloud based REST API that helps developers to generate new barcode images from scratch, recognize barcodes from images, specify barcode text attributes, set barcode image characteristics like width, height, border style, output format etc. Developers can create barcode using more than 40 symbologies like (1D) EAN13, EAN8, UPCA, UPCE barcode, MSI & Code11 (2D) like PDF417, DataMatrix, Aztec, QR, Italian Post 25 & postal types like Postnet, Planet, USPS OneCode & many more.

More about Saaspose.BarCode

- Homepage of Saaspose.BarCode
- Saaspose.BarCode REST Live Examples
- More Technical Tips by Saaspose.BarCode
- Ask technical questions/queries from Saaspose Support Team

Contact Information
Aspose Pty Ltd, Suite 163,
79 Longueville Road
Lane Cove, NSW, 2066
Australia
Saaspose - Your File Format Experts 2.0
[email protected]
Phone: 1.214.329.1520
Fax: 866.810.9465
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sher azam wrote:
This technical tip allows developers to read barcode from external image URL using Saaspose.BarCode REST API in your Java applications. Some important steps for performing this task is to build URI for reading barcode, sending the request to Saaspose server, parsing and Deserializes the JSON to an object and display the value and type of all the recognized barcodes.

Sample Code for Reading Barcode from external image URL

//build URI to read barcode
//type: Codabar, Code11, Code128 and Code39Extended etc.
String strURI = "http://api.saaspose.com/v1.0/barcode/recognize?type=QR&url=http://upload.wikimedia.org/wikipedia/commons/c/ce/WikiQRCode.png";
// Send the request to Saaspose server
InputStream responseStream = ProcessCommand(Sign(strURI), "POST");
// Read the response
String strJSON = StreamToString(responseStream);
//Parse and Deserializes the JSON to a object.
RecognitionResponse barcodeRecognitionResponse = gson.fromJson(strJSON,RecognitionResponse.class);
List<RecognizedBarCode> barcodes = barcodeRecognitionResponse.getBarcodes();

// Display the value and type of all the recognized barcodes
for (RecognizedBarCode barcode : barcodes)
{
System.out.println("Codetext: " + barcode.BarcodeValue() + "\nType: " + barcode.getBarcodeType());
}

\\Here is the RecognitionResponse class
public class RecognitionResponse extends BaseResponse
{
private List<RecognizedBarCode> Barcodes ;
public List<RecognizedBarCode> getBarcodes(){return Barcodes;}
}

\\Here is the RecognizedBarCode class
public class RecognizedBarCode
{
private String BarcodeType ;
private String BarcodeValue;
public String getBarcodeType(){return BarcodeType;}
public String BarcodeValue(){return BarcodeValue;}
}

\\Here is the BaseResponse class
public class BaseResponse
{
public BaseResponse() { }
private String Code;
private String Status;
public String getCode(){return Code;}
public String getStatus(){return Status;}
public void setCode(String temCode){ Code=temCode;}
public void setStatus(String temStatus){ Status=temStatus;}
}

Overview: Saaspose.Barcode

Saaspose.Barcode is a cloud based REST API that helps developers to generate new barcode images from scratch, recognize barcodes from images, specify barcode text attributes, set barcode image characteristics like width, height, border style, output format etc. Developers can create barcode using more than 40 symbologies like (1D) EAN13, EAN8, UPCA, UPCE barcode, MSI & Code11 (2D) like PDF417, DataMatrix, Aztec, QR, Italian Post 25 & postal types like Postnet, Planet, USPS OneCode & many more.



Thank you, very useful code sample. Can I tested qr code and code 39. but I can't scan pdf 417, I don't know what's wrong with it? Any help?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic