USING IRONBARCODE

How to Print A Barcode Label in VB .NET

Barcode labels are crucial in inventory management, product tracking, and supply chain operations. In this article, we will learn barcode printing in VB.NET using IronBarcode. Whether you’re a seasoned developer or just starting, we’ll explore the ways of creating and printing barcode labels efficiently. From designing label templates to handling printer settings, our step-by-step approach will empower you to generate accurate and visually appealing labels for your business needs.

How to Print Barcode Labels in VB.NET

  1. Create or open a project in Visual Studio
  2. Generate the barcode
  3. Resize the barcode
  4. Add a barcode value and annotation text
  5. Style the barcode

Why Barcode Labels Matter

Before we dive into the technical details, let’s understand why barcode labels matter:

  1. Efficient Data Representation: Barcodes encode essential information such as product IDs, batch numbers, expiration dates, and pricing. When scanned, they provide instant access to relevant data, streamlining processes across various industries.
  2. Error Reduction: Manual data entry is prone to errors. Barcode labels eliminate the risk of human mistakes, ensuring accurate data capture during inventory management, sales transactions, and shipping.
  3. Supply Chain Optimization: Barcodes facilitate seamless tracking of goods throughout the supply chain. From manufacturers to retailers, everyone benefits from standardized labeling.

Why VB.NET and IronBarcode?

VB.NET is a powerful and versatile programming language, perfect for automating tasks like label printing. However, it doesn't have built-in barcode generation capabilities. That's where IronBarcode comes in, a library that provides all the barcode-related functionalities. Integrate it into your project, and you're ready to utilize the barcode power!

IronBarcode

IronBarcode is a powerful .NET library that simplifies barcode generation and manipulation. Whether you’re building inventory management systems, retail applications, or supply chain solutions, IronBarcode provides a seamless way to create, read, and print barcodes. With support for various barcode symbologies (such as Code 39, QR codes, and UPC), customizable settings, and straightforward integration into your VB.NET or C# projects, IronBarcode empowers developers to handle barcode-related tasks efficiently. Its intuitive API allows you to generate accurate and visually appealing barcode labels, enhancing data accuracy and streamlining business processes.

Generating and Printing Barcodes

We will write the code to generate and print barcodes in a VB.NET project. First, you need to create or open a VB.NET project, then install the IronBarcode library. I will use a Console Application for this example; however, you may use any project type as per your requirements as this code works for all project types.

Installing IronBarcode Library

To seamlessly integrate the IronBarcode library into your project via the Package Manager Console, follow this step-by-step procedure for a smooth installation process:

  1. Open your Visual Studio project.
  2. Click on Tools in the menu.
  3. Select NuGet Package Manager.
  4. Choose Package Manager Console.
  5. In the console, type the following command and press Enter:

    Install-Package Barcode
    Install-Package Barcode
    SHELL
  6. This command will download and install the IronBarcode package for you.

How to Print A Barcode Label in VB .NET: Figure 1 - Console messages documenting IronBarcode installation

IronBarcode is free for development purposes but requires a license to explore all its functionality.

Generating a Barcode Image

Write the following code to generate a Barcode.

Imports IronBarCode

Module Program
    Sub Main(args As String())
        ' Creating a barcode is simple:
        Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
        ' Save the barcode as an image:
        myBarcode.SaveAsImage("myBarcode.jpeg")
    End Sub
End Module
Imports IronBarCode

Module Program
    Sub Main(args As String())
        ' Creating a barcode is simple:
        Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
        ' Save the barcode as an image:
        myBarcode.SaveAsImage("myBarcode.jpeg")
    End Sub
End Module
VB .NET

This code simplifies the process of generating a barcode image using the IronBarcode library. It shows how to create a barcode and save it as an image, essentially turning data into a scannable picture.

  • Import IronBarCode: This line allows our program to use the features provided by the IronBarcode library.
  • Create Barcode: Generates a barcode for the value "123456BCX65432" using Code 128 encoding. A barcode is a unique pattern of lines and spaces that represents specific information.
  • Save Image: Saves the barcode as an image file named "myBarcode.jpeg". This file contains the visual representation of the barcode, which can be printed or displayed.

Output

How to Print A Barcode Label in VB .NET: Figure 2 - Outputted barcode from the previous code example

Let's resize the barcode to fit into the printable area.

Resizing the Barcode Image

The following code will resize the barcode as per the provided dimension.

Sub Main(args As String())
    ' Creating a barcode is simple:
    Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
    ' Resize the Barcode:
    myBarcode.ResizeTo(400, 100)
    ' Save our barcode as an image:
    myBarcode.SaveAsImage("myBarcode.jpeg")
End Sub
Sub Main(args As String())
    ' Creating a barcode is simple:
    Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
    ' Resize the Barcode:
    myBarcode.ResizeTo(400, 100)
    ' Save our barcode as an image:
    myBarcode.SaveAsImage("myBarcode.jpeg")
End Sub
VB .NET

The process of creating a barcode remains the same. We just added a line to resize the image before saving. This adjusts its dimensions to be 400 pixels wide and 100 pixels tall, ensuring that it fits well within the desired space when displayed or printed.

Output

How to Print A Barcode Label in VB .NET: Figure 3 - The resized barcode image from the previous code

Let's add the Barcode Value and annotation text below or above our barcode.

Adding a Barcode Value and Annotation

The following source code adds a Barcode Value and annotation text above and below the barcode, respectively.

Sub Main(args As String())
    ' Creating a barcode is simple:
    Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
    ' Resize the Barcode:
    myBarcode.ResizeTo(400, 100)
    ' Add an annotation text above the barcode
    myBarcode.AddAnnotationTextAboveBarcode("This is my test barcode generated using IronBarcode.")
    ' Add the actual barcode value below the barcode
    myBarcode.AddBarcodeValueTextBelowBarcode()
    ' Save our barcode as an image:
    myBarcode.SaveAsImage("myBarcode.jpeg")
End Sub
Sub Main(args As String())
    ' Creating a barcode is simple:
    Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
    ' Resize the Barcode:
    myBarcode.ResizeTo(400, 100)
    ' Add an annotation text above the barcode
    myBarcode.AddAnnotationTextAboveBarcode("This is my test barcode generated using IronBarcode.")
    ' Add the actual barcode value below the barcode
    myBarcode.AddBarcodeValueTextBelowBarcode()
    ' Save our barcode as an image:
    myBarcode.SaveAsImage("myBarcode.jpeg")
End Sub
VB .NET

The code for creating, resizing, and saving the barcode remains the same. We've added extra lines for annotation and value text.

  • Add Annotation: This line adds extra text above the barcode to provide additional context or information.
  • Add Barcode Value: Displays the actual value represented by the barcode beneath it.

Output Barcode Image

How to Print A Barcode Label in VB .NET: Figure 4 - Annotated barcode with a barcode value

Let's style our barcode by changing the background and barcode color.

Style Barcode

The following code will change the background color and the barcode color.

Sub Main(args As String())
    Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
    myBarcode.ResizeTo(400, 100)
    myBarcode.AddAnnotationTextAboveBarcode("This is my test barcode generated using Iron Barcode.")
    myBarcode.AddBarcodeValueTextBelowBarcode()
    ' Change the barcode's color
    myBarcode.ChangeBarCodeColor(IronSoftware.Drawing.Color.DarkBlue)
    ' Change the background color
    myBarcode.ChangeBackgroundColor(IronSoftware.Drawing.Color.Cornsilk)
    ' Save our styled barcode as an image:
    myBarcode.SaveAsImage("myStyledBarcode.jpeg")
End Sub
Sub Main(args As String())
    Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
    myBarcode.ResizeTo(400, 100)
    myBarcode.AddAnnotationTextAboveBarcode("This is my test barcode generated using Iron Barcode.")
    myBarcode.AddBarcodeValueTextBelowBarcode()
    ' Change the barcode's color
    myBarcode.ChangeBarCodeColor(IronSoftware.Drawing.Color.DarkBlue)
    ' Change the background color
    myBarcode.ChangeBackgroundColor(IronSoftware.Drawing.Color.Cornsilk)
    ' Save our styled barcode as an image:
    myBarcode.SaveAsImage("myStyledBarcode.jpeg")
End Sub
VB .NET

The basic barcode creation steps remain unchanged. We've added lines to alter the appearance of the barcode with a different color.

  • Barcode Color: Changes the barcode's lines and spaces to a Dark Blue color for better visual distinction.
  • Background Color: Sets the background to Cornsilk, ensuring the barcode stands out clearly.

Output

How to Print A Barcode Label in VB .NET: Figure 5 - Styled barcode from the previous code

This generates a styled barcode image. You can use the print dialogue in .NET Winforms if you're developing a Windows Forms application.

Conclusion

In this comprehensive guide, we've explored the essential role of barcode labels in data representation, error reduction, and supply chain optimization. Leveraging the power of VB.NET and the IronBarcode library, developers can seamlessly generate, read, manipulate, and print barcodes. The step-by-step approach covers installation, barcode generation, resizing, annotation addition, and styling, providing a versatile toolkit for creating accurate and visually appealing labels.

Whether you're a seasoned developer or just starting, this guide equips you to enhance efficiency in inventory management, sales transactions, and supply chain operations, making barcode integration a valuable asset for business applications.

IronBarcode offers a free trial for extended and production use.

Frequently Asked Questions

What is the purpose of barcode labels?

Barcode labels are crucial for inventory management, product tracking, and supply chain operations. They encode essential information and streamline processes by providing instant access to relevant data, minimizing human errors, and optimizing supply chain operations.

Why should I use VB.NET with IronBarcode for barcode generation?

VB.NET is a versatile programming language ideal for automating tasks like label printing. IronBarcode complements VB.NET by providing all the barcode-related functionalities, as it simplifies barcode generation and manipulation with its library.

How do I install the IronBarcode library in my VB.NET project?

To install IronBarcode in your VB.NET project, open Visual Studio, navigate to Tools > NuGet Package Manager > Package Manager Console, and run the command 'Install-Package Barcode' to download and install the IronBarcode package.

How can I generate a barcode image using IronBarcode in VB.NET?

To generate a barcode image, you can use IronBarcode's API to create a barcode object with specified data and encoding, then save it as an image file using methods provided by the library.

Is it possible to resize the barcode image using IronBarcode?

Yes, you can resize the barcode image using IronBarcode. The library provides methods to adjust the dimensions of a barcode to fit specific requirements before saving it as an image.

How do I add annotation text and barcode value to a barcode image?

Using IronBarcode, you can add annotation text above or below the barcode by invoking methods like 'AddAnnotationTextAboveBarcode' and 'AddBarcodeValueTextBelowBarcode' to include additional information or the actual barcode value.

Can I change the color of the barcode and its background using IronBarcode?

Yes, IronBarcode allows you to change the barcode's color and background color using methods like 'ChangeBarCodeColor' and 'ChangeBackgroundColor' to enhance visual appeal and distinction.

Is IronBarcode free to use?

IronBarcode is free for development purposes, but it requires a license for extended and production use. A free trial is available to explore all its functionalities.

What types of barcodes can be created with IronBarcode?

IronBarcode supports various barcode symbologies, including Code 39, QR codes, and UPC, allowing developers to generate a wide range of barcode types for different applications.

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.
< PREVIOUS
How To Create a Blazor QR Code Scanner
NEXT >
How to use the VB .NET For Barcode Reader Component