How to generate a UPC-A barcode as a PNG file in Java

1 min readAug 5, 2020

Java may not be the ideal platform for creating barcode images, but that is about to change. Today’s post will cover how to set this up almost instantly, and have you generating UPC-A barcodes in real time after just a few minutes. Let’s dive straight in.

First we are going to add our repository reference for our API client library:


Following that, we need our dependency reference:


Finally, our function call, which we can provide with our barcode value for encoding:

// Import classes://import com.cloudmersive.client.invoker.ApiClient;//import com.cloudmersive.client.invoker.ApiException;//import com.cloudmersive.client.invoker.Configuration;//import com.cloudmersive.client.invoker.auth.*;//import com.cloudmersive.client.GenerateBarcodeApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");Apikey.setApiKey("YOUR API KEY");// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.setApiKeyPrefix("Token");GenerateBarcodeApi apiInstance = new GenerateBarcodeApi();String value = "value_example"; // String | UPC-A barcode value to generate fromtry {File result = apiInstance.generateBarcodeUPCA(value);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling GenerateBarcodeApi#generateBarcodeUPCA");e.printStackTrace();}

And you’re done!




There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.