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

Today’s tutorial is going to showcase an unbelievably simple solution for UPC-E barcode generation for Java users. By taking this approach instead of trying to manually code your barcode creation, you will be saving yourself hours and probably a few gray hairs to boot. Let’s get right to it.

First we need the following repository reference for jipack.

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

Then comes our dependency.

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.54</version>
</dependency>
</dependencies>

And finally, we can call our function like this:

// 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-E barcode value to generate fromtry {File result = apiInstance.generateBarcodeUPCE(value);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling GenerateBarcodeApi#generateBarcodeUPCE");e.printStackTrace();}

That’s it! Barcode generation is now yours to command.

Image for post
Image for post

Written by

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store