Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
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.
Before we dive into the technical details, let’s understand why barcode labels matter:
VB.NET is a powerful and versatile programming language, perfect for automating tasks like label printing. But 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 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.
Now, we will write the code to generate and print barcodes in the VB.NET project. First of all, you need to create or open a VB.NET project. Then you need to install the IronBarcode library. I will be using the Console Application for this project, however, you may use any project type as per your requirements as this code works for all project types.
To seamlessly integrate the IronBarcode library into your project via the Package Manager Console, simply execute the following step-by-step procedure for a smooth installation process:
In the console, type the following command and press Enter:
Install-Package BarCode
IronBarcode is free for development purposes but requires a license to explore all its functionality.
Write the following code to generate a Barcode.
Imports IronBarCode
Module Program
Private Sub Main(args As String())
' Creating a barcode is as simple as:
Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
' And save our barcode as in image:
myBarcode.SaveAsImage("myBarcode.jpeg")
End Sub
End Module
Imports IronBarCode
Module Program
Private Sub Main(args As String())
' Creating a barcode is as simple as:
Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
' And save our barcode as in image:
myBarcode.SaveAsImage("myBarcode.jpeg")
End Sub
End Module
The above code simplifies the process of generating a barcode image. It shows how to use the IronBarcode library to create a barcode and save it as an image. It’s like turning a piece of data into a scannable picture! The explanation is as:
Let's resize our barcode to fit to printable area.
The following code will resize our barcode as per the provided dimension.
Private Sub Main(args As String())
' Creating a barcode is as simple as:
Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
' Resize the Barcoce:
myBarcode.ResizeTo(400, 100)
' And save our barcode as in image:
myBarcode.SaveAsImage("myBarcode.jpeg")
End Sub
Private Sub Main(args As String())
' Creating a barcode is as simple as:
Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
' Resize the Barcoce:
myBarcode.ResizeTo(400, 100)
' And save our barcode as in image:
myBarcode.SaveAsImage("myBarcode.jpeg")
End Sub
The Process of Creating a barcode remains the same. We have just an additional line of code to resize the image before saving. The second line of code resizes the barcode. We adjust its dimensions to be 400 pixels wide and 100 pixels tall. This step ensures that the barcode fits well within the desired space when displayed or printed.
The Output is as:
Let's add the Barcode Value and annotation text below or above our barcode.
The following source code will add a Barcode Value, and Annotation text below and above the barcode respectively.
Private Sub Main(args As String())
' Creating a barcode is as simple as:
Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
' Resize the Barcoce:
myBarcode.ResizeTo(400, 100)
myBarcode.AddAnnotationTextAboveBarcode("This is my test barcode generated using Iron Barcode.")
myBarcode.AddBarcodeValueTextBelowBarcode()
' And save our barcode as in image:
myBarcode.SaveAsImage("myBarcode.jpeg")
End Sub
Private Sub Main(args As String())
' Creating a barcode is as simple as:
Dim myBarcode = BarcodeWriter.CreateBarcode("123456BCX65432", BarcodeWriterEncoding.Code128)
' Resize the Barcoce:
myBarcode.ResizeTo(400, 100)
myBarcode.AddAnnotationTextAboveBarcode("This is my test barcode generated using Iron Barcode.")
myBarcode.AddBarcodeValueTextBelowBarcode()
' And save our barcode as in image:
myBarcode.SaveAsImage("myBarcode.jpeg")
End Sub
The code for creating, resizing, and saving barcodes remains the same. We have just added two additional lines for adding annotation text and value.
The third line of code adds an annotation (text) above the barcode. The annotation says: “This is my test barcode generated using Iron Barcode.” Annotations provide additional context or information about the barcode.
The fourth line of code adds the actual barcode value below the barcode. For example, if the barcode represents a product ID, this text would display the product ID.
The barcode generated is as:
Let's style our barcode by changing the background and barcode color.
The following code will change the background color and the image color.
myBarcode.ChangeBarCodeColor(IronSoftware.Drawing.Color.DarkBlue)
myBarcode.ChangeBackgroundColor(IronSoftware.Drawing.Color.Cornsilk)
myBarcode.ChangeBarCodeColor(IronSoftware.Drawing.Color.DarkBlue)
myBarcode.ChangeBackgroundColor(IronSoftware.Drawing.Color.Cornsilk)
The code for creating barcodes remains the same, We have added additional lines to change the background color and barcode color.
The first line of code modifies the color of the barcode itself. We set the barcode color to Dark Blue using the ChangeBarCodeColor method. This means that the lines and spaces in the barcode will appear in a dark blue hue.
The second line of code adjusts the background color behind the barcode. We set the background color to a light shade called Cornsilk using the ChangeBackgroundColor method. This ensures that the barcode stands out clearly against the background.
The output is as:
This will generate a barcode image, you can now use the print Dialogue Box of .NET Winforms if you are developing an application for Windows Forms.
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.
9 .NET API products for your office documents