Manipulate Barcodes using Java REST API

In today’s fast-paced economies, BarCodes are an essential and viable solution for vendors and merchants for storing product details. Over the years, they have proved to be a valuable and viable choice for businesses. They have greatly improved efficiency and have reduced overhead. The barcodes are both cost-effective and reliable. Among other benefits of using BarCode, specified below are few more advantages of using them

  • Barcodes eliminate the possibility of human error
  • Using a barcode system reduces employee training time
  • Barcodes are extremely versatile and can be used for any kind of necessary data collection
  • They enable precise inventory control, and hence Inventory control improves
  • Furthermore, the Barcodes provide better data i.e. a single barcode may provide inventory and pricing details

Pertinent to all such features, Aspose.BarCode Cloud Java SDK empowers Java developers to create as well as manipulate BarCodes using Java language. Similar to our other Cloud APIs, Aspose.BarCode Cloud Java SDK requires you to register an account at Cloud Dashboard. If you already have registered an account, you may continue using it. Once you have your account ready, you are good to use the Cloud Services through AppKey and AppSID.

You may consider using Aspose Cloud storage or, use any third-party cloud storage services for file storage and retrieval.

Supported formats

The SDK supports numerous Barcode symbologies (more than 60) such as EAN, UPC, Codabar, PDF417, QR, MicroQR, Postnet, Planet, RM4SCC, etc. You also get the option to load existing BarCode information and save the output into popular image formats, such as  JPEG, PNG, GIF, BMP, TIFF, EMF, WMF, SVG, EXIF, and ICON. For a complete list of supported symbologies, please visit Aspose.BarCode Cloud Java SDK.

Generate Barcode

The SDK offers you to create Linear, 2D, and postal barcode images in a plathora of formats. You can specify barcode image attributes like image width, height, border style, and output image format. You may also specify the barcode type and text attributes such as text location and font styles as per your application requirements. It also provides the capabilities to set the height of bars & rotate barcode images at an angle.

The following example shows the steps to create Code39Standard Barcode, placed on the Top-Center alignment of the page. The text color is specified as Navy, Horizontal, and Vertical resolution is specified as 200. The BarColor is specified as Orange, the background color is set as silver and the output format is JPEG format.

Before we proceed further, we recommend you to visit following link as JWT token is necessary when accessing the API using cURL command.

cURL

curl -X PUT "https://api.aspose.cloud/v3.0/barcode/MySample.jpeg/generate?Type=Code39Standard&Text=BarCode%20processing&TextLocation=Above&TextAlignment=Center&TextColor=Navy&FontSizeMode=Auto&Resolution=200&ResolutionX=200&BackColor=silver&BarColor=Orange&BorderColor=Blue&format=jpeg" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>"

Request URL

https://api.aspose.cloud/v3.0/barcode/MySample.jpeg/generate?Type=Code39Standard&Text=BarCode%20processing&TextLocation=Above&TextAlignment=Center&TextColor=Navy&FontSizeMode=Auto&Resolution=200&ResolutionX=200&BackColor=silver&BarColor=Orange&BorderColor=Blue&format=jpeg

Java

Output generated with Aspose.BarCode Cloud Java SDK
Image 1:- Resultant BarCode preview.

Recognize Barcodes

The Cloud API is also capable of recognizing information from existing barcodes. You get the option to specify the Barcode type details for quick retrieval or let the API to determine the type automatically. You may also specify ChecksumValidation details, DetectEncoding, or let the API determine them over the runtime.

cURL

curl -X POST "https://api.aspose.cloud/v3.0/barcode/recognize?Type=all&DetectEncoding=true" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: multipart/form-data" \
-H  "x-aspose-client: Containerize.Swagger" -d {"image":{}}

Request URL

https://api.aspose.cloud/v3.0/barcode/recognize?Type=all&DetectEncoding=true

Java

Image with Barcode
Image 2:- Image with sample Barcode.

If you run the above code on the above-specified image, the Response body will render output as

Response body

{
  "barcodes": [
    {
      "barcodeValue": "12345678",
      "type": "Code39Standard",
      "region": [
        {
          "x": 28,
          "y": 3
        },
        {
          "x": 222,
          "y": 3
        },
        {
          "x": 222,
          "y": 74
        },
        {
          "x": 28,
          "y": 74
        }
      ],
      "checksum": ""
    }
  ]
}

Conclusion

In this article, we have learned about the features and steps to manipulate Barcodes using Java REST API.