Saltar al pie de página
USO DE IRONBARCODE

Cómo Imprimir una Etiqueta de Código de Barras en 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.

Preguntas Frecuentes

¿Cómo inicio un proyecto VB.NET para imprimir códigos de barras?

Para comenzar un proyecto VB.NET para la impresión de códigos de barras, inicia un nuevo proyecto en Visual Studio. Luego, instala la biblioteca IronBarcode utilizando la Consola del Administrador de Paquetes NuGet con el comando Install-Package Barcode.

¿Qué pasos están involucrados en la generación de etiquetas de código de barras usando VB.NET?

Generar etiquetas de código de barras en VB.NET implica configurar un proyecto en Visual Studio, instalar IronBarcode, crear un objeto de código de barras con los datos deseados y usar métodos para estilizar y guardar el código de barras como una imagen.

¿Cómo puedo personalizar la apariencia de una imagen de código de barras en VB.NET?

IronBarcode permite la personalización de la apariencia de un código de barras proporcionando métodos para cambiar los colores del código de barras y del fondo, agregar texto de anotación y cambiar el tamaño del código de barras para cumplir con requisitos específicos.

¿Qué simbologías de código de barras admite la biblioteca?

La biblioteca IronBarcode admite una variedad de simbologías de código de barras, incluyendo Code 39, códigos QR y UPC, lo que la hace versátil para diferentes necesidades de generación de códigos de barras.

¿Puede usarse IronBarcode en proyectos tanto de VB.NET como de C#?

Sí, IronBarcode es compatible con proyectos tanto de VB.NET como de C#, proporcionando una solución robusta para la generación y manipulación de códigos de barras en diferentes lenguajes .NET.

¿Hay una versión de prueba disponible para la biblioteca de códigos de barras?

Sí, IronBarcode ofrece una versión de prueba gratuita que permite a los desarrolladores explorar sus funcionalidades para un uso prolongado, aunque se requiere una licencia para el despliegue en producción.

¿Cómo puedo agregar texto de anotación a una imagen de código de barras en VB.NET?

Puedes agregar texto de anotación a una imagen de código de barras usando IronBarcode empleando métodos como AddAnnotationTextAboveBarcode para colocar el texto sobre el código de barras o AddBarcodeValueTextBelowBarcode para mostrar el valor del código de barras.

¿Cuáles son los beneficios de usar códigos de barra en la gestión de inventarios?

Los códigos de barras en la gestión de inventario optimizan las operaciones al proporcionar acceso rápido a los datos, reducir los errores de entrada manual y optimizar el seguimiento y la gestión del inventario mediante una representación eficiente de datos.

¿Cómo puedo asegurarme de que mis etiquetas de código de barras se impriman con precisión en VB.NET?

Para garantizar una impresión precisa de las etiquetas de código de barras en VB.NET, diseña las plantillas de etiquetas correctamente, configura los ajustes de la impresora de manera adecuada y utiliza IronBarcode para generar códigos de barras de alta calidad adaptados a las necesidades de tu negocio.

Jordi Bardia
Ingeniero de Software
Jordi es más competente en Python, C# y C++. Cuando no está aprovechando sus habilidades en Iron Software, está programando juegos. Compartiendo responsabilidades para pruebas de productos, desarrollo de productos e investigación, Jordi agrega un valor inmenso a la mejora continua del producto. La experiencia variada lo mantiene ...
Leer más