How to generate a EAN-13 barcode as a PNG file in C# .NET Framework
1 min readMar 22, 2020
Today we are going to tackle EAN-13 barcodes using C# within .NET Framework. This normally painful process will be simplified immensely by judicious use of one of our APIs that is tailor-made for this situation.
Kicking things off, we are going to install our barcode client via NuGet:
Install-Package Cloudmersive.APIClient.NET.Barcode -Version 2.0.2
Next, call our function for EAN-13.
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 GenerateBarcodeEAN13Example{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 | Barcode value to generate fromtry{// Validates and generate a EAN-13 barcode as a PNG file, a type of 1D barcodeSystem.IO.Stream result = apiInstance.GenerateBarcodeEAN13(value);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling GenerateBarcodeApi.GenerateBarcodeEAN13: " + e.Message );}}}}
Enter your desired string and the API will send back a PNG of your finished barcode, no further work necessary! Easy.