USING IRONBARCODE

Using a Barcode Reader SDK for .NET

Jordi Bardia
Jordi Bardia
April 3, 2025
Share:

Barcode scanning is an essential feature for many applications, from inventory management to retail and logistics. By integrating barcode reading into your .NET applications, you can streamline data capture, automate workflows, and improve efficiency.

IronBarcode is a powerful .NET library that makes working with barcodes simple. With this tool, you can read barcodes from images, streams, and PDF files, as well as generate QR codes. This article will show you how to integrate barcode scanning into your .NET application, focusing on creating an API or Web App integration to expose barcode scanning functionality.

Best Use Cases for IronBarcode Integration

IronBarcode is ideal for:

  • Inventory management systems – Automate barcode scanning to track products and stock levels.
  • Logistics applications – Process scanned barcode images for shipping, receiving, and package tracking.
  • Retail POS systems – Validate barcode scans for sales transactions and price lookups.
  • Document processing – Extract barcode data from PDF invoices, receipts, or ID cards.

How to Create a Barcode Reader SDK in .NET

To create a barcode reader that can be exposed as a service in your application, you will integrate IronBarcode into a REST API or Web App. Below is an example of how to do this using ASP.NET Core.

  1. Install the .NET library for reading barcodes in C#
  2. Create a reusable barcode scanning class.
  3. Develop methods for reading barcodes from different sources.
  4. Integrate barcode image reading into your application.
  5. Test and optimize performance.

Before We Start

If you haven’t already, download IronBarcode for your project. Make sure you have the proper license key for your intended use. Note that exposing IronBarcode’s functionality via a public API or reselling it as a standalone service requires additional licensing (SDK, OEM, or SaaS). Ensure you understand the licensing considerations before proceeding.

Creating a Barcode Scanner Class

Once you have set up IronBarcode and installed it in your project, you can create a reusable barcode scanner class that integrates IronBarcode’s functionality and exposes it as an API endpoint.

using IronBarCode;
using System.IO;
namespace BarcodeIntegration
{
    public class BarcodeScanner
    {
        static BarcodeScanner()
        {
            // Set the license key
            IronBarCode.License.LicenseKey = "Your-License-Key";
        }
        // Read a barcode from an image file
        public string ReadBarcodeFromImage(string imagePath)
        {
            try
            {
                var barcode = BarcodeReader.Read(imagePath);
                return barcode?.ToString() ?? "No Barcode Found";
            }
            catch (Exception ex)
            {
                return $"Error reading barcode: {ex.Message}";
            }
        }
        // Read a barcode from a stream (e.g., file upload or memory stream)
        public string ReadBarcodeFromStream(Stream inputStream)
        {
            try
            {
                var barcode = BarcodeReader.Read(inputStream);
                return barcode?.ToString() ?? "No barcode found";
            }
            catch (Exception ex)
            {
                return $"Error reading barcode: {ex.Message}";
            }
        }
        // Read a barcode from a PDF file
        public string ReadBarcodeFromPdf(string filePath)
        {
            try
            {
                var barcode = BarcodeReader.ReadPdf(filePath);
                return barcode?.ToString() ?? "No barcode found";
            }
            catch (Exception ex)
            {
                return $"Error reading barcode: {ex.Message}";
            }
        }
    }
}
using IronBarCode;
using System.IO;
namespace BarcodeIntegration
{
    public class BarcodeScanner
    {
        static BarcodeScanner()
        {
            // Set the license key
            IronBarCode.License.LicenseKey = "Your-License-Key";
        }
        // Read a barcode from an image file
        public string ReadBarcodeFromImage(string imagePath)
        {
            try
            {
                var barcode = BarcodeReader.Read(imagePath);
                return barcode?.ToString() ?? "No Barcode Found";
            }
            catch (Exception ex)
            {
                return $"Error reading barcode: {ex.Message}";
            }
        }
        // Read a barcode from a stream (e.g., file upload or memory stream)
        public string ReadBarcodeFromStream(Stream inputStream)
        {
            try
            {
                var barcode = BarcodeReader.Read(inputStream);
                return barcode?.ToString() ?? "No barcode found";
            }
            catch (Exception ex)
            {
                return $"Error reading barcode: {ex.Message}";
            }
        }
        // Read a barcode from a PDF file
        public string ReadBarcodeFromPdf(string filePath)
        {
            try
            {
                var barcode = BarcodeReader.ReadPdf(filePath);
                return barcode?.ToString() ?? "No barcode found";
            }
            catch (Exception ex)
            {
                return $"Error reading barcode: {ex.Message}";
            }
        }
    }
}
Imports IronBarCode
Imports System.IO
Namespace BarcodeIntegration
	Public Class BarcodeScanner
		Shared Sub New()
			' Set the license key
			IronBarCode.License.LicenseKey = "Your-License-Key"
		End Sub
		' Read a barcode from an image file
		Public Function ReadBarcodeFromImage(ByVal imagePath As String) As String
			Try
				Dim barcode = BarcodeReader.Read(imagePath)
				Return If(barcode?.ToString(), "No Barcode Found")
			Catch ex As Exception
				Return $"Error reading barcode: {ex.Message}"
			End Try
		End Function
		' Read a barcode from a stream (e.g., file upload or memory stream)
		Public Function ReadBarcodeFromStream(ByVal inputStream As Stream) As String
			Try
				Dim barcode = BarcodeReader.Read(inputStream)
				Return If(barcode?.ToString(), "No barcode found")
			Catch ex As Exception
				Return $"Error reading barcode: {ex.Message}"
			End Try
		End Function
		' Read a barcode from a PDF file
		Public Function ReadBarcodeFromPdf(ByVal filePath As String) As String
			Try
				Dim barcode = BarcodeReader.ReadPdf(filePath)
				Return If(barcode?.ToString(), "No barcode found")
			Catch ex As Exception
				Return $"Error reading barcode: {ex.Message}"
			End Try
		End Function
	End Class
End Namespace
$vbLabelText   $csharpLabel

This BarcodeScanner class abstracts IronBarcode’s functionality, making it easy to integrate into any .NET application. Let's look at a breakdown of the different methods included here:

Methods to Read Barcodes

Each of the following methods attempts to read a barcode from different types of input:

  • ReadBarcodeFromImage(string imagePath): Reads a barcode from an image file.
  • ReadBarcodeFromStream(Stream inputStream): Reads a barcode from an input stream (e.g., file upload or memory stream).
  • ReadBarcodeFromPdf(string filePath): Reads a barcode from a PDF file.

Each method attempts to read the barcode data and returns the barcode string or an error message if no barcode is found or an exception occurs.

Exposing Barcode Reading via a REST API

To allow external applications to use your barcode scanning functionality, you can expose it as a REST API using ASP.NET Core. Below is an example of how you might do this:

using Microsoft.AspNetCore.Mvc;
using System.IO;
using Microsoft.AspNetCore.Http;
using BarcoderReader;
[ApiController]
[Route("api/barcode")]
public class BarcodeController : ControllerBase
{
    private readonly BarcodeScanner _barcodeScanner;
    public BarcodeController()
    {
        _barcodeScanner = new BarcodeScanner();
    }
    [HttpPost("read-from-image")]
    public IActionResult ReadFromImage(IFormFile file)
    {
        using var stream = file.OpenReadStream();
        var result = _barcodeScanner.ReadBarcodeFromStream(stream);
        return Ok(new { Barcode = result });
    }
}
using Microsoft.AspNetCore.Mvc;
using System.IO;
using Microsoft.AspNetCore.Http;
using BarcoderReader;
[ApiController]
[Route("api/barcode")]
public class BarcodeController : ControllerBase
{
    private readonly BarcodeScanner _barcodeScanner;
    public BarcodeController()
    {
        _barcodeScanner = new BarcodeScanner();
    }
    [HttpPost("read-from-image")]
    public IActionResult ReadFromImage(IFormFile file)
    {
        using var stream = file.OpenReadStream();
        var result = _barcodeScanner.ReadBarcodeFromStream(stream);
        return Ok(new { Barcode = result });
    }
}
Imports Microsoft.AspNetCore.Mvc
Imports System.IO
Imports Microsoft.AspNetCore.Http
Imports BarcoderReader
<ApiController>
<Route("api/barcode")>
Public Class BarcodeController
	Inherits ControllerBase

	Private ReadOnly _barcodeScanner As BarcodeScanner
	Public Sub New()
		_barcodeScanner = New BarcodeScanner()
	End Sub
	<HttpPost("read-from-image")>
	Public Function ReadFromImage(ByVal file As IFormFile) As IActionResult
		Dim stream = file.OpenReadStream()
		Dim result = _barcodeScanner.ReadBarcodeFromStream(stream)
		Return Ok(New With {Key .Barcode = result})
	End Function
End Class
$vbLabelText   $csharpLabel

Swagger UI

Using a Barcode Reader SDK for .NET: Figure 1 Add from PixabayUpload

or drag and drop an image here

Add image alt text

Output

Using a Barcode Reader SDK for .NET: Figure 2 Add from PixabayUpload

or drag and drop an image here

Add image alt text

This API exposes a POST endpoint where barcode images can be uploaded, and the API will return the barcode data. This allows other systems or front-end applications to interact with your barcode scanner as a service.

Advanced Features

To further enhance the SDK, consider adding:

  1. Support for Multiple Barcode Types: IronBarcode supports the ability to read multiple barcodes. You can add options to configure your SDK to accept multiple barcodes at once. For example:
public string ReadBarcodeFromImage(string imagePath)
{
    try
    {
        BarcodeReaderOptions options = new BarcodeReaderOptions()
        {
            ExpectMultipleBarcodes = true,
            ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional,
        };
        foreach (var barcode in BarcodeReader.Read(imagePath, options))
        {
            return barcode.ToString();
        }
        return "No barcode found";
    }
    catch (Exception ex)
    {
        return $"Error reading barcode: {ex.Message}";
    }
}
public string ReadBarcodeFromImage(string imagePath)
{
    try
    {
        BarcodeReaderOptions options = new BarcodeReaderOptions()
        {
            ExpectMultipleBarcodes = true,
            ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional,
        };
        foreach (var barcode in BarcodeReader.Read(imagePath, options))
        {
            return barcode.ToString();
        }
        return "No barcode found";
    }
    catch (Exception ex)
    {
        return $"Error reading barcode: {ex.Message}";
    }
}
Public Function ReadBarcodeFromImage(ByVal imagePath As String) As String
	Try
		Dim options As New BarcodeReaderOptions() With {
			.ExpectMultipleBarcodes = True,
			.ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional
		}
		For Each barcode In BarcodeReader.Read(imagePath, options)
			Return barcode.ToString()
		Next barcode
		Return "No barcode found"
	Catch ex As Exception
		Return $"Error reading barcode: {ex.Message}"
	End Try
End Function
$vbLabelText   $csharpLabel
  1. Error Handling: Expand error handling and logging to provide better diagnostics for your SDK users.

  2. Batch Processing: If you want to process multiple barcodes from a collection of images, you can create methods that take in an array of images or streams.

  3. Customization: Offer configuration options for barcode detection parameters, such as accuracy, speed, and supported barcode types.

Licensing Considerations

As mentioned earlier, the IronBarcode SDK is meant for integration into your internal applications, and exposing it through an API requires additional licensing. You must secure the necessary licensing (SDK, OEM, or SaaS) before exposing IronBarcode as part of a service, such as a public API.

Do not resell IronBarcode as a standalone SDK or expose it via a public-facing API without ensuring that your licensing covers this usage.

Try IronBarcode Free Today

Experience the innovative power of IronBarcode. Try our free trial and discover seamless barcode generation, reading, and editing for your .NET applications. With advanced features, exceptional performance, and a user-friendly interface, IronBarcode is the ultimate solution for all your barcode needs. Start your free trial today and elevate your projects.

Jordi Bardia
Software Engineer
Jordi is most proficient in Python, C# and C++, when he isn’t leveraging his skills at Iron Software; he’s game programming. Sharing responsibilities for product testing, product development and research, Jordi adds immense value to continual product improvement. The varied experience keeps him challenged and engaged, and he says it’s one of his favorite aspects of working with Iron Software. Jordi grew up in Miami, Florida and studied Computer Science and Statistics at University of Florida.
NEXT >
How to Read Multiple Barcodes with IronBarcode: Live Demo Recap