USING IRONBARCODE

How to Generate Barcodes in VB .NET

Published April 3, 2024
Share:

Barcodes play a crucial role in modern applications, facilitating efficient data tracking and management. In the world of .NET development, there numerous barcode generator SDK available and various extensions can be found on Visual Studio marketplace as well. IronBarcode stands out as a powerful library for generating and reading barcodes. How cool it would be to have a barcode generating .NET windows application using IronBarcode.

In this article, we will explore how to create a barcode generator in VB.NET using IronBarcode, a versatile tool that simplifies barcode handling within your applications.

How to Generate Barcodes in VB.NET

  1. Create VB.NET Console Application in Visual Studio
  2. Install IronBarcode Library using NuGet
  3. Add Reference to IronBarcode Library in Program.vb file
  4. Create Barcode using BarcodeWriter.CreateBarcode Method
  5. Save Barcode using SaveAsImage Method

IronBarcode - The Ultimate .NET Barcode Generator DLL

IronBarcode, part of the Iron software product line, provides a comprehensive set of functionalities for working with barcodes in .NET applications. It supports various barcode formats, including QR codes, UPC, EAN, Code 128, and more. With its user-friendly API, IronBarcode makes it easy to generate barcodes, read, and customize them in VB.NET projects.

Features of IronBarcode:

Here are some important key features of IronBarcode that makes it a number one contender for generating barcodes in Visual Basic:

  1. Barcode Generation: IronBarcode enables the creation of a wide range of barcode types, including QR code, 2D Data Matrix barcodes, and various linear barcodes.
  2. Barcode Reading: The library allows developers to read barcodes from images, PDFs, and other sources, providing automatic rotation and perspective correction.
  3. Styling Options: IronBarcode offers extensive styling options, allowing developers to customize the appearance of barcodes, add text annotations, and include logos.
  4. Output Formats: Barcodes can be exported in various formats, including images (PNG, JPEG), PDF, HTML, and more.
  5. Compatibility: IronBarcode is compatible with a range of .NET languages, including VB.NET, and supports multiple platforms such as .NET Core, .NET Standard, and .NET Framework.

Steps to Create a VB.NET Console Project in Visual Studio

  1. Open Visual Studio and select "Create a new project."
  2. Choose "Console App (.NET Core/.NET Framework)" as the project template.
  3. Set a name for your project and click "Next."

    How to Generate Barcodes in VB .NET: Figure 1 - Specify the Project name and Location for your project.

  4. From Additional Information, choose the appropriate .NET version. IronBarcode supports the latest 8.0 version so you can choose that without any hesitation.

Install IronBarcode via NuGet Package Manager Console or Solutions

To integrate IronBarcode into your VB.NET project to generate linear barcodes, follow these steps:

  • NuGet Package Manager Console:

    • Open the NuGet Package Manager Console from the tools menu in Visual Studio.
    • Run the following command to install IronBarcode:
    Install-Package BarCode
    • Solution Explorer:
    • Right-click on your project in Solution Explorer.
    • Select "Manage NuGet Packages."
    • Search for "Barcode" in the browse tab and install the IronBarcode package.

How to Generate Barcodes in VB .NET: Figure 2 - Install IronBarcode using the Manage NuGet Package for Solution by searching "IronBarcode" in the search bar of NuGet Package Manager, then select the project and click on the Install button.

Steps to Generate Barcode in VB.NET

Now that IronBarcode is integrated in VB.NET console application, let's create barcode using IronBarcode that generates a barcode.

  1. Importing Libraries:

    Imports IronBarCode
    Imports System.IO
    Imports IronBarCode
    Imports System.IO
    VB.NET

    In the first two lines, necessary libraries are imported. IronBarCode provides the functionality for working with barcodes, and System.IO is imported for handling input/output operations.

  2. Creating a Simple Barcode:

    Private myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8)
    Private myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8)
    VB.NET

    Here, a barcode is created with the value "12345" and the encoding type EAN8 using BarcodeWriter.CreateBarcode method. The resulting barcode is stored in the myBarcode variable.

  3. Saving the Barcode as an Image:

    myBarcode.SaveAsImage("EAN8.jpeg")
    myBarcode.SaveAsImage("EAN8.jpeg")
    VB.NET

    The generated barcode (myBarcode) is saved as an image file named "EAN8.jpeg" using the SaveAsImage method.

  4. One-Liner for Creating and Saving Barcode:

    BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8).ResizeTo(400, 100).SaveAsImage("EAN8.jpeg")
    BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8).ResizeTo(400, 100).SaveAsImage("EAN8.jpeg")
    VB.NET

    This line combines the barcode creation, resizing (to 400x100), and saving into a single line of code.

  5. Creating a barcode from binary data (byte array)

    Dim payloadAsString As String = "This is some random string"
        Dim payloadAsByteArray() As Byte = System.Text.Encoding.Default.GetBytes(payloadAsString)
        Dim AztecBarcode = BarcodeWriter.CreateBarcode(payloadAsByteArray, BarcodeWriterEncoding.Aztec, 400, 400)
        AztecBarcode.SaveAsImage("AztecBarcode.png")
    Dim payloadAsString As String = "This is some random string"
        Dim payloadAsByteArray() As Byte = System.Text.Encoding.Default.GetBytes(payloadAsString)
        Dim AztecBarcode = BarcodeWriter.CreateBarcode(payloadAsByteArray, BarcodeWriterEncoding.Aztec, 400, 400)
        AztecBarcode.SaveAsImage("AztecBarcode.png")
    VB.NET

    Here, we convert a string to a byte array (payloadAsByteArray) and then create a barcode (AztecBarcode) using the Aztec encoding type with dimensions 400x400.

  6. Creating a barcode from binary data (MemoryStream)

    Dim payloadAsStream As New MemoryStream(payloadAsByteArray)
        Dim AztecBarcode2 = BarcodeWriter.CreateBarcode(payloadAsStream, BarcodeWriterEncoding.Aztec, 400, 400)
    Dim payloadAsStream As New MemoryStream(payloadAsByteArray)
        Dim AztecBarcode2 = BarcodeWriter.CreateBarcode(payloadAsStream, BarcodeWriterEncoding.Aztec, 400, 400)
    VB.NET

    In this step, we create a MemoryStream from the byte array and then generate another barcode (AztecBarcode2) using the Aztec encoding type with dimensions 400x400.

  7. Saving the Barcode in multiple formats

    MyBarCode.SaveAsImage("MyBarCode.png")
        MyBarCode.SaveAsGif("MyBarCode.gif") MyBarCode.SaveAsHtmlFile("MyBarCode.html") MyBarCode.SaveAsJpeg("MyBarCode.jpg")
        MyBarCode.SaveAsPdf("MyBarCode.Pdf")
        MyBarCode.SaveAsPng("MyBarCode.png")
        MyBarCode.SaveAsTiff("MyBarCode.tiff") MyBarCode.SaveAsWindowsBitmap("MyBarCode.bmp")
    MyBarCode.SaveAsImage("MyBarCode.png")
        MyBarCode.SaveAsGif("MyBarCode.gif") MyBarCode.SaveAsHtmlFile("MyBarCode.html") MyBarCode.SaveAsJpeg("MyBarCode.jpg")
        MyBarCode.SaveAsPdf("MyBarCode.Pdf")
        MyBarCode.SaveAsPng("MyBarCode.png")
        MyBarCode.SaveAsTiff("MyBarCode.tiff") MyBarCode.SaveAsWindowsBitmap("MyBarCode.bmp")
    VB.NET

    These lines demonstrate how the generated barcode (MyBarCode) can be saved in various image formats such as PNG, GIF, HTML, JPEG, PDF, TIFF, and Windows Bitmap. IronBarcode provides flexibility in choosing the desired output format for the generated barcode.

Each step demonstrates different ways to create barcodes with IronBarcode, whether from simple values, binary data, or in a concise one-liner. The source code showcases the flexibility and ease of use offered by IronBarcode in VB Programming.

For more controlled barcode generation and styling, please visit this code examples page.

The complete Visual Basic sample code goes as follows:

Imports IronBarCode
Imports System.IO
Module Program
    Sub Main(args As String())
        ' Creating a barcode is as simple as:
        Dim myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8)
        ' And save our barcode as an image:
        myBarcode.SaveAsImage("EAN8.jpeg")
        ' OR, we can do both steps on one line:
        BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8).ResizeTo(400, 100).SaveAsImage("EAN8.jpeg")
        ' Barcode can also be made from from Binary data (byte or stream)
        Dim payloadAsString As String = "This is some random string"
        Dim payloadAsByteArray() As Byte = System.Text.Encoding.Default.GetBytes(payloadAsString) ' Byte Array
        Dim AztecBarcode = BarcodeWriter.CreateBarcode(payloadAsByteArray, BarcodeWriterEncoding.Aztec, 400, 400) ' Create from Byte Array
        Dim payloadAsStream As New MemoryStream(payloadAsByteArray) ' MemoryStream
        Dim AztecBarcode2 = BarcodeWriter.CreateBarcode(payloadAsStream, BarcodeWriterEncoding.Aztec, 400, 400) ' Create from Memory Stream
        AztecBarcode.SaveAsImage("AztecBarcode.png")
    End Sub
End Module
Imports IronBarCode
Imports System.IO
Module Program
    Sub Main(args As String())
        ' Creating a barcode is as simple as:
        Dim myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8)
        ' And save our barcode as an image:
        myBarcode.SaveAsImage("EAN8.jpeg")
        ' OR, we can do both steps on one line:
        BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8).ResizeTo(400, 100).SaveAsImage("EAN8.jpeg")
        ' Barcode can also be made from from Binary data (byte or stream)
        Dim payloadAsString As String = "This is some random string"
        Dim payloadAsByteArray() As Byte = System.Text.Encoding.Default.GetBytes(payloadAsString) ' Byte Array
        Dim AztecBarcode = BarcodeWriter.CreateBarcode(payloadAsByteArray, BarcodeWriterEncoding.Aztec, 400, 400) ' Create from Byte Array
        Dim payloadAsStream As New MemoryStream(payloadAsByteArray) ' MemoryStream
        Dim AztecBarcode2 = BarcodeWriter.CreateBarcode(payloadAsStream, BarcodeWriterEncoding.Aztec, 400, 400) ' Create from Memory Stream
        AztecBarcode.SaveAsImage("AztecBarcode.png")
    End Sub
End Module
VB.NET

Output Barcode Image

Upon running the VB.NET console application, a barcode image file ("EAN8.jpeg") and a QR code type AztecBarcode image file ("AztecBarcode.png") will be created in the project folder.

How to Generate Barcodes in VB .NET: Figure 3 - Output: EAN8 barcode image

How to Generate Barcodes in VB .NET: Figure 4 - Output: Aztec barcode image

IronBarcode can also be easily integrated to .NET Windows Forms and also ASP.NET Web projects.

Conclusion

In this article, we've explored how to create a VB.NET barcode generator using the IronBarcode library. By following the steps outlined, developers can seamlessly integrate barcode generation capabilities into their VB.NET applications, enhancing data tracking and management. IronBarcode's rich feature set and straightforward API make it a valuable tool for barcode-related tasks in the .NET ecosystem.

For more detailed information on IronBarcode and its usage, please visit the documentation page.

IronBarcode is free for development purposes, however it needs to be licensed to test out its full potential in handling barcode images in VB.NET Barcode applications. Download the library from here and give it a try.

< PREVIOUS
Creating a Razor Barcode Generator Web App
NEXT >
How to Add a Barcode in Crystal Reports using C#

Ready to get started? Version: 2024.10 just released

Free NuGet Download Total downloads: 1,246,703 View Licenses >