How to generate a UPC-A barcode as a PNG file in C# .NET Framework

Today we are going to take the pain and suffering out of creating UPC-A barcodes. I suppose it’s not all that bad, but why do all that work if you don’t have to? We have a handy dandy API that can generate that barcode for you, and the whole process takes almost no time at all.

First, install the barcode API with this Package Manager command:

Install-Package Cloudmersive.APIClient.NET.Barcode -Version 2.0.2

From there, call the function for UPC-A codes, like so:

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.Barcode.Api;using Cloudmersive.APIClient.NET.Barcode.Client;using Cloudmersive.APIClient.NET.Barcode.Model;namespace Example{public class GenerateBarcodeUPCAExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new GenerateBarcodeApi();var value = value_example;  // string | UPC-A barcode value to generate fromtry{// Validate and generate a UPC-A barcode as a PNG file, a type of 1D barcodeSystem.IO.Stream result = apiInstance.GenerateBarcodeUPCA(value);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling GenerateBarcodeApi.GenerateBarcodeUPCA: " + e.Message );}}}}

All done! Any string entered in will be converted into a PNG of the barcode and sent back. Seriously, why would you do this any other way?

Image for post
Image for post

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