Skip to footer content
USING IRONBARCODE

How to Print Barcodes in Crystal Reports with VB.NET

To print barcodes in Crystal Reports with VB.NET, install IronBarcode via NuGet, generate barcode images using BarcodeWriter.CreateBarcode(), and bind the resulting binary data to an image field in your Crystal Report. This approach eliminates font dependencies and produces scannable, print-ready barcodes in minutes.

Adding barcodes to Crystal Reports can enhance your business processes, making them faster and more accurate -- from tracking inventory to generating detailed reports. If you have ever tried using font-based barcodes in VB.NET, you know how tricky it can be with the complex formulas, limited formats, and printer issues that can make it frustrating.

Modern barcode generator SDKs such as IronBarcode make creating and printing barcodes straightforward. In this guide, you will find everything you need: setting up IronBarcode in Visual Studio, generating barcodes, and displaying them directly in your Crystal Reports. By the end, you will be able to produce professional, reliable barcodes with minimal hassle.

What Are the Methods for Printing Barcodes in Crystal Reports?

Two primary approaches exist for adding barcodes to Crystal Reports: font-based methods and SDK solutions.

Font-based methods require installing special barcode fonts (True Type fonts) in your fonts folder and using formulas or a User Function Library (UFL) to encode data. While this approach works, it often involves complex encoding formulas, limited barcode format support (such as Code 39 or data matrix), and potential font rendering issues across different printers and systems, as discussed in Microsoft's documentation on font rendering.

SDK-based solutions provide a more dependable alternative. These libraries generate barcode images programmatically, offering better reliability, extensive format support, and easier implementation. IronBarcode exemplifies this modern approach, allowing developers to generate barcodes as images that integrate with Crystal Reports through standard database fields or DataTable objects. This method ensures consistent rendering across all platforms and eliminates font dependency issues when printing a barcode in a Crystal Report using VB.NET.

Font-Based vs. SDK-Based Barcode Methods in Crystal Reports
Factor Font-Based Method SDK-Based Method (IronBarcode)
Setup complexity High -- requires font installation and encoding formulas Low -- single NuGet package install
Barcode format support Limited (Code 39, Code 128) 30+ formats including QR, Data Matrix, PDF417
Cross-printer consistency Inconsistent -- depends on installed fonts Consistent -- image-based rendering
Maintenance burden High -- fonts must be managed per machine Low -- managed via NuGet updates
Scanning reliability Variable High -- IronBarcode generates verified images

How Do You Install IronBarcode for VB.NET?

Setting up IronBarcode in your VB.NET project requires minimal configuration. First, install the library through NuGet Package Manager by running:

Install-Package BarCode
Install-Package BarCode
SHELL

Alternatively, use the Package Manager UI in Visual Studio to search for and install "BarCode". Once installed, import the namespace in your VB.NET code:

Imports IronBarCode

Ensure your project targets .NET Framework 4.6.2 or higher, or any version of .NET Core, .NET 5, or .NET 6+. IronBarcode works with all Crystal Reports versions that support image fields, making it broadly compatible with existing projects. For detailed setup instructions, refer to the IronBarcode getting started guide.

Download IronBarcode today to start creating professional barcodes in your Crystal Reports.

What .NET Versions Does IronBarcode Support?

IronBarcode targets a wide range of .NET runtimes:

  • .NET Framework 4.6.2 and above
  • .NET Core 3.1+
  • .NET 5, 6, 7, 8, and 9
  • .NET Standard 2.0+

This broad compatibility means you can integrate IronBarcode into legacy VB.NET applications running on .NET Framework just as easily as modern applications targeting .NET 8 or later. Check the IronBarcode compatibility documentation for the full support matrix.

How Do You Generate Barcodes and Store Them in a Database?

Creating barcodes with IronBarcode and storing them for Crystal Reports involves generating the barcode image and saving it to your database using a SqlConnection or OleDbConnection. Here is a complete example:

Option 1: Using a SQL Database

Imports IronBarCode
Imports System.Data.SqlClient

Module BarcodeGenerator
    Sub CreateAndStoreBarcode()
        ' Generate a Code128 barcode
        Dim myBarcode = BarcodeWriter.CreateBarcode("PROD-12345", BarcodeWriterEncoding.Code128)
        ' Add readable text below the barcode
        myBarcode.AddBarcodeValueTextBelowBarcode()
        ' Resize to appropriate dimensions
        myBarcode.ResizeTo(400, 150)
        ' Connect to your database
        Using connection As New SqlConnection("YourConnectionString")
            Dim cmd As New SqlCommand(
                "INSERT INTO Products (ProductCode, BarcodeImage) VALUES (@Code, @Image)",
                connection)
            cmd.Parameters.AddWithValue("@Code", "PROD-12345")
            cmd.Parameters.AddWithValue("@Image", myBarcode.BinaryStream)
            connection.Open()
            cmd.ExecuteNonQuery()
        End Using
    End Sub
End Module

This example generates a Code 128 barcode and stores it as binary data in SQL Server. The AddBarcodeValueTextBelowBarcode() method adds human-readable text beneath the barcode symbol, making it usable for both scanning and visual inspection. The ResizeTo() method adjusts dimensions to fit your report layout.

Option 2: Using a DataTable

For scenarios where you do not need persistent storage, a DataTable approach avoids the database entirely:

Imports IronBarCode
Imports System.Data

Function CreateBarcodeDataTable() As DataTable
    Dim dt As New DataTable()
    dt.Columns.Add("ProductCode", GetType(String))
    dt.Columns.Add("Barcode", GetType(Byte()))

    ' Generate a barcode for each product
    Dim row As DataRow = dt.NewRow()
    row("ProductCode") = "PROD-12345"

    Dim barcode = BarcodeWriter.CreateBarcode("PROD-12345", BarcodeWriterEncoding.Code128)
    barcode.AddBarcodeValueTextBelowBarcode()
    barcode.ResizeTo(400, 150)
    row("Barcode") = barcode.BinaryStream

    dt.Rows.Add(row)
    Return dt
End Function

This DataTable approach is ideal for report previews, one-time print jobs, or when database infrastructure is not available. You can loop through a product list and add a row for each item, generating barcodes on demand. For more barcode formats, explore the supported barcode types or browse the IronBarcode tutorials.

How Do You Customize Barcode Appearance?

Beyond simple generation, IronBarcode provides several customization options useful in print reports:

  • Margins -- Use myBarcode.SetMargins() to add white space around the barcode, improving scan reliability
  • Colors -- Change foreground and background colors for branded report designs
  • Annotations -- Add custom text above or below the barcode using AddBarcodeValueTextAboveBarcode()
  • Resolution -- Set DPI for high-quality print output using myBarcode.SetDPI()

Refer to the barcode customization guide for code examples covering each option.

How Do You Display Barcodes in Crystal Reports?

Once barcodes are stored in your database, displaying them in Crystal Reports follows standard image field procedures:

  1. Open Crystal Reports and create a new report or open an existing one
  2. In Field Explorer, right-click "Database Fields" and select "Database Expert"

    How to Print Barcodes in Crystal Reports with VB.NET: Figure 1 - Database expert window

  3. Connect to your database and select the table containing barcode images
  4. Drag the barcode image field onto your report design surface
  5. Resize and position the field as needed

Your report designer should look similar to this:

How to Print Barcodes in Crystal Reports with VB.NET: Figure 2 - report designer layout

For dynamic barcode generation during report runtime, modify your DataTable or database query to generate barcodes on the fly. The following example shows how to bind a dynamically created DataTable to a CrystalReportViewer:

Imports IronBarCode
Imports System.Data

Function GetReportData() As DataTable
    Dim dt As New DataTable()
    dt.Columns.Add("ProductCode", GetType(String))
    dt.Columns.Add("Barcode", GetType(Byte()))

    Dim row As DataRow = dt.NewRow()
    row("ProductCode") = "CUSTOMER-12345"

    Dim barcode = BarcodeWriter.CreateBarcode("CUSTOMER-12345", BarcodeWriterEncoding.Code128)
    barcode.AddBarcodeValueTextBelowBarcode()
    barcode.ResizeTo(400, 150)
    row("Barcode") = barcode.BinaryStream

    dt.Rows.Add(row)
    Return dt
End Function

This approach generates barcodes dynamically when the report loads, eliminating the need to pre-store images in the database. You can export reports to PDF using Crystal Reports' built-in export features. For more information about Crystal Reports data sources, see SAP's Crystal Reports documentation.

Output

Your Crystal Report will display the barcode with readable text and proper dimensions. Adjust field size or margins as needed for scanners, printers, or labels. The barcode can be included in PDF, printed forms, or label templates directly from your VB.NET application.

How to Print Barcodes in Crystal Reports with VB.NET: Figure 3 - Displaying generated barcodes with Crystal Reports Viewer

How Do You Handle Common Barcode Printing Issues?

Several issues may arise when implementing barcodes in Crystal Reports using VB.NET. The following troubleshooting tips address the most frequent problems:

Common Issues and Solutions for Crystal Reports Barcode Printing
Issue Cause Solution
Blurry barcodes Low image resolution Use ResizeTo() with larger dimensions or set higher DPI
Scanning failures Insufficient quiet zone Add margins with SetMargins(); add asterisks for Code 39
Database connection errors Incorrect connection parameters Verify OleDbConnection or SqlConnection string and dataset binding
Wrong data type in database Field not set to binary type Use image or varbinary(max) column type
Barcodes not displaying Permission or path issue Verify Crystal Reports viewer has database/DataTable access permissions
Missing DLL errors Incomplete installation Reinstall via NuGet; verify IronBarcode DLL is referenced in project

For additional troubleshooting support, visit the IronBarcode troubleshooting guide. The IronBarcode support forum is also available for specific questions and edge cases not covered in the documentation.

How Do You Choose the Right Barcode Format?

Choosing the correct barcode format matters for scanning hardware compatibility and data capacity. The most common formats for business reporting are:

  • Code 128 -- General-purpose linear barcode; high data density; works with most scanners. Use BarcodeWriterEncoding.Code128.
  • Code 39 -- Older standard; widely supported; encodes alphanumeric characters. Use BarcodeWriterEncoding.Code39.
  • QR Code -- 2D barcode; stores large amounts of data including URLs. Use BarcodeWriterEncoding.QRCode.
  • Data Matrix -- Compact 2D barcode; common in manufacturing and logistics. Use BarcodeWriterEncoding.DataMatrix.
  • PDF417 -- High-capacity 2D barcode; used for shipping labels and IDs. Use BarcodeWriterEncoding.PDF417.

Refer to the full supported barcode formats list when selecting the appropriate encoding for your use case. For reading barcodes from Crystal Report output images, see the barcode reader tutorial.

What Are Your Next Steps?

Implementing barcodes in Crystal Reports using VB.NET and IronBarcode provides a dependable solution for report enhancement. This SDK-based approach eliminates font dependencies while offering extensive customization options. Whether using a database or a DataTable, you can implement professional barcodes -- including Data Matrix, Code 39, and QR codes -- in your Crystal Reports application.

To continue building your barcode workflow:

Start implementing barcodes in your project today by exploring IronBarcode's free trial to explore its full capabilities for printing barcodes in Crystal Reports using VB.NET. The SAP Crystal Reports SDK is documented at the SAP developer portal for additional integration patterns.

Frequently Asked Questions

What are the benefits of using IronBarcode in Crystal Reports with VB.NET?

Using IronBarcode in Crystal Reports with VB.NET allows you to integrate barcodes seamlessly, enhancing business processes for tasks like tracking inventory and generating detailed reports. It simplifies barcode generation compared to font-based solutions.

How does IronBarcode improve barcode generation in Crystal Reports?

IronBarcode improves barcode generation by providing a straightforward SDK that eliminates the need for complex formulas and reduces issues related to limited formats and printer compatibility in Crystal Reports.

Can IronBarcode handle different barcode formats in Crystal Reports?

Yes, IronBarcode supports a wide range of barcode formats, making it versatile for various applications within Crystal Reports, ensuring compatibility and reliability.

Is it difficult to integrate IronBarcode into a VB.NET project?

No, integrating IronBarcode into a VB.NET project is designed to be user-friendly with clear documentation and support, making the process smooth and efficient.

Why should I choose IronBarcode over font-based barcode solutions?

IronBarcode provides a more robust and flexible solution than font-based barcodes, avoiding complex formulas and printer issues, and offering extensive format support and reliability.

Does IronBarcode support barcode printing directly from Crystal Reports?

Yes, IronBarcode allows direct barcode printing from Crystal Reports, ensuring high-quality output and reducing the complexity often associated with other methods.

What are the common issues with font-based barcodes in VB.NET?

Font-based barcodes often involve complex formulas, limited format options, and printer compatibility issues, which IronBarcode helps to overcome with its comprehensive SDK.

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 ...
Read More

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me