Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
Barcodes are a powerful means to represent data in a visible, computer-readable format. In this tutorial, we’ll explore how to generate and read barcodes using IronBarcode in Visual Basic. IronBarcode provides a robust and efficient solution, whether you’re building an inventory management system, a point-of-sale application, or any other project involving VB.NET barcode reader handling.
IronBarcode is a powerful C# library that seamlessly integrates with VB.NET (Visual Basic) projects. It provides robust functionality for reading and writing barcode images, making it an excellent choice for developers working with VB.NET barcode reader component applications. This guide will cover the basics of reading barcodes, configuring options, and handling multiple barcodes in a single scan.
Read()
method.ReadPdf()
method.CreateBarcode()
method with specified Barcode Encoding.IronBarcode is a powerful C# barcode library that simplifies working with barcodes in .NET applications. Whether you need to create barcodes or read existing ones, IronBarcode provides an intuitive and efficient solution.
Here are some key features and use cases of IronBarcode:
Barcode Generation: IronBarcode allows developers to easily generate various types of barcodes, including 1D barcodes like Code 39, Code 128, and UPC, as well as 2D barcodes like QR codes and Data Matrix.
Barcode Reading: The library includes functionality to read barcodes from images, PDFs, or other sources. This can be useful for applications that need to process barcode values from scanned documents or camera captures.
Encoding and Decoding: IronBarcode supports encoding and decoding of barcode values, providing developers with the ability to manipulate barcode scanning information programmatically.
Supported Barcode Types: IronBarcode supports a wide range of barcode symbologies, making it versatile for different application requirements.
Ease of Use: The library is designed to be user-friendly and easy to integrate into .NET applications. It provides comprehensive documentation and examples to assist developers in implementing barcode-related functionality.
The first step is to open or create a new project. The project can be of any type. The same code works for all project types. The next step is to install the IronBarcode library in our project.
You can install the IronBarcode NuGet Package using the Package Manager Console. Enter the following command:
Install-Package BarCode
The above command will download and install the IronBarcode Library with all necessary dependencies.
Alternatively, you can also download it from the Manage NuGet package for the solution by browsing it.
Let's proceed further to generate a barcode image using VB.NET.
Creating barcodes is straightforward. You can use the BarcodeWriter
class to generate various types of barcodes. Once we have our barcode, we can save it as an image. The barcode image can be accessed as an Image or converted to a Bitmap. We’ll create a simple Code128 barcode with the value “0987654ABCD0987654”. Here’s how you can do it:
Sub Main(args As String())
Dim myBarcode = BarcodeWriter.CreateBarcode("0987654ABCD0987654", BarcodeWriterEncoding.Code128)
' Save the barcode as an image
myBarcode.SaveAsImage("myCode128Barcode.jpeg")
End Sub
Sub Main(args As String())
Dim myBarcode = BarcodeWriter.CreateBarcode("0987654ABCD0987654", BarcodeWriterEncoding.Code128)
' Save the barcode as an image
myBarcode.SaveAsImage("myCode128Barcode.jpeg")
End Sub
The above code snippet utilizes the IronBarcode library to generate a Code 128 barcode with the data "0987654ABCD0987654". The BarcodeWriter.CreateBarcode
method is employed, specifying the Code128 encoding. Subsequently, the created barcode is saved as a JPEG image file named "myCode128Barcode.jpeg" using the SaveAsImage
method. The ability to change the BarcodeWriterEncoding
parameter allows for flexibility in selecting different barcode symbologies according to specific needs, with options such as EAN13, EAN8, Code Bar, MSI, ITF, PDF417, QR codes, or Data Matrix codes offered by the IronBarcode library.
If you wish to save the generated barcode in formats other than JPEG, the IronBarcode library provides various methods for different file formats. You can use methods like SaveAsHtmlFile
, SaveAsPDF
, SaveAsTiff
, SaveAsPng
, and others, depending on your requirements. For example, if you want to save the barcode as an HTML file, you can replace the SaveAsImage
line with myBarcode.SaveAsHtmlFile("myCode128Barcode.html")
. Similarly, for other formats, you can use the corresponding methods, providing the desired file name and extension. This flexibility enables the adaptation of the generated barcode to different file formats to suit specific application needs.
The generated barcode image is as:
After creating a barcode, you can resize it easily. The following code will set its max width to 650 pixels and max height to 300 pixels.
Dim myBarcode = BarcodeWriter.CreateBarcode("0987654ABCD0987654", BarcodeWriterEncoding.Code128)
myBarcode.ResizeTo(650, 300)
' Save the resized barcode as an image
myBarcode.SaveAsImage("myCode128Barcode.jpeg")
Dim myBarcode = BarcodeWriter.CreateBarcode("0987654ABCD0987654", BarcodeWriterEncoding.Code128)
myBarcode.ResizeTo(650, 300)
' Save the resized barcode as an image
myBarcode.SaveAsImage("myCode128Barcode.jpeg")
The ResizeTo
method is used to resize a barcode image. In the provided example, myBarcode.ResizeTo(650, 300)
is applied to the myBarcode
object, suggesting that the barcode image is being resized to a width of 650 pixels and a height of 300 pixels.
This method is beneficial when you need to adjust the dimensions of the generated barcode image to meet specific requirements or to ensure it fits appropriately within a given layout or display area. Resizing can be useful in scenarios where you need to control the visual presentation of the barcode in terms of its size without altering the encoded data.
The output is as:
IronBarcode makes reading barcodes simple. You can extract barcode values from different sources:
ReadPdf
).The following code will scan the barcode image and print its value in the console.
Sub Main(args As String())
Dim resultFromImage = BarcodeReader.Read("myCode128Barcode.jpeg") ' Scan barcodes
For i As Integer = 0 To resultFromImage.Count - 1
Console.WriteLine("Barcode Value: {0}", resultFromImage(i))
Next i
End Sub
Sub Main(args As String())
Dim resultFromImage = BarcodeReader.Read("myCode128Barcode.jpeg") ' Scan barcodes
For i As Integer = 0 To resultFromImage.Count - 1
Console.WriteLine("Barcode Value: {0}", resultFromImage(i))
Next i
End Sub
The above code utilizes the IronBarcode library to read barcode data from an image file, "myCode128Barcode.jpeg." The BarcodeReader.Read
method extracts the barcode information, and a loop is used to iterate through the results. The barcode values are then printed to the console using Console.WriteLine
.
Additionally, you can also scan barcode data from various sources such as Bitmaps, AnyBitmaps, image files, and streams. These options provide flexibility in handling barcode data from different input formats, ranging from conventional image files like BMP and JPG to more generic representations like AnyBitmaps and streams. With this, we can develop our very own .NET Barcode reader, which reads barcodes and returns the result.
The output is displayed as:
We can add more advanced features to our barcode scanners, such as customizing barcode scanning using BarcodeReaderOptions. Set parameters such as:
We will read the following PDF file having three different barcode images.
The following code will add advanced features to our VB.NET barcode reader.
Sub Main(args As String())
Dim resultFromPdf = BarcodeReader.ReadPdf("Barcode.pdf") ' Scan barcodes from a PDF
Dim myOptionsExample As New BarcodeReaderOptions() With {
.Speed = ReadingSpeed.Balanced,
.ExpectMultipleBarcodes = True,
.ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional,
.Multithreaded = True,
.MaxParallelThreads = 2,
.CropArea = New System.Drawing.Rectangle(),
.UseCode39ExtendedMode = True
}
For i As Integer = 0 To resultFromPdf.Count - 1
Console.WriteLine("Barcode Value - {0} = {1}", i, resultFromPdf(i))
Next i
End Sub
Sub Main(args As String())
Dim resultFromPdf = BarcodeReader.ReadPdf("Barcode.pdf") ' Scan barcodes from a PDF
Dim myOptionsExample As New BarcodeReaderOptions() With {
.Speed = ReadingSpeed.Balanced,
.ExpectMultipleBarcodes = True,
.ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional,
.Multithreaded = True,
.MaxParallelThreads = 2,
.CropArea = New System.Drawing.Rectangle(),
.UseCode39ExtendedMode = True
}
For i As Integer = 0 To resultFromPdf.Count - 1
Console.WriteLine("Barcode Value - {0} = {1}", i, resultFromPdf(i))
Next i
End Sub
The above code scans barcodes from a PDF file, "Barcode.pdf." The BarcodeReader.ReadPdf
method extracts barcode information from the PDF, and a loop is utilized to iterate through the results. Additionally, the code introduces a BarcodeReaderOptions
object, myOptionsExample
, configured with various settings such as reading speed, the expectation of multiple barcodes, accepting all one-dimensional barcode types, enabling multithreading with a maximum of two parallel threads, specifying a crop area, and using Code 39 extended mode. These options demonstrate the flexibility of the IronBarcode library in customizing the barcode reading process based on specific requirements and environmental considerations. The barcode values are then printed to the console, providing insights into the decoded data from the PDF file.
The output is displayed as:
In this way, we can create our own .NET barcode scanner DLL.
In conclusion, this tutorial demonstrated how to create a barcode scanner and generator in VB.NET using the IronBarcode library. IronBarcode offers a robust solution for handling barcode-related tasks, whether generating options for purchase, making it a flexible and accessible tool for incorporating barcode capabilities into VB.NET projects.
IronBarcode is a powerful C# library that integrates seamlessly with VB.NET projects. It provides robust functionality for reading and writing barcode images, making it an excellent choice for developers working with VB.NET barcode reader component applications.
To read barcodes using VB.NET, you first need to install the IronBarcode library. Then, you can use methods like 'Read()' to read barcode images from files or 'ReadPdf()' to read barcodes from PDF files.
You can generate barcodes in VB.NET by installing the IronBarcode library and using the 'CreateBarcode()' method, specifying the desired barcode encoding. The resulting barcode can be saved as an image or PDF.
IronBarcode supports a wide range of barcode symbologies, including 1D barcodes like Code 39, Code 128, and UPC, as well as 2D barcodes like QR codes and Data Matrix.
You can install the IronBarcode NuGet Package using the Package Manager Console with the command 'Install-Package BarCode'. Alternatively, you can download it from the Manage NuGet package for the solution by browsing it.
Yes, IronBarcode can handle multiple barcodes in a single scan. You can configure this by setting options such as 'ExpectMultipleBarcodes' in 'BarcodeReaderOptions'.
You can enhance your barcode scanner with advanced features by utilizing 'BarcodeReaderOptions'. This allows you to set reading speed, expect multiple barcodes, specify barcode types, enable multithreading, and define crop areas for focused scanning.
To resize barcode images, you can use the 'ResizeTo' method provided by IronBarcode. This method allows you to set a maximum width and height for the barcode image.
Saving barcodes in different file formats allows for flexibility in how they are used or shared. IronBarcode provides methods to save barcodes as images, PDF, HTML, TIFF, and PNG, among others, to suit various application needs.
To create a barcode scanner in VB.NET, start by installing the IronBarcode library. Then, use 'BarcodeReader' methods to scan images or PDFs for barcodes, and configure additional scanning options as needed using 'BarcodeReaderOptions'.