Displaying a QR code in Crystal Reports is a common requirement in modern business applications—especially for invoices, labels, ID cards, tickets, and tracking documents. While Crystal Reports does not include a built-in QR code generator, you can easily display QR codes by generating them in C# and passing them to the report as images.
This post walks you step-by-step through:- Generating a QR code in C#
- Passing the QR code to Crystal Reports
- Displaying the QR code in the report
- Common pitfalls and troubleshooting tips
Display QR code in Crystal Reports
Getting Started
QR codes have become an essential part of modern business applications, enabling fast access to digital information through a simple scan. Whether you're generating invoices, product labels, ID cards, shipment documents, or authentication tokens, integrating QR codes directly into your reports can greatly enhance automation and user experience. However, Crystal Reports does not offer a built-in QR code generator, which leaves developers searching for reliable ways to embed QR images dynamically.
Fortunately, with C# and a lightweight QR code library, you can easily generate QR codes at runtime and display them inside Crystal Reports just like any other image. In this guide, we walk through the complete process—from generating the QR code in C#, converting it into a format Crystal Reports can recognize, and binding it to a report for clean, professional output.
Standard Approach of the Solution
- Generate the QR code image in C#
- Save it to a byte[] or file
- Bind it to a dataset field (image/BLOB field)
- Place an Image object in Crystal Reports and bind it to that field.
Install a Crystal Report QRCode library
There isn’t a large number of NuGet packages specifically tailored to Crystal Reports + QR code, but there are some good ones (and some general-purpose QR-barcode libraries) you can use, depending on how you plan to embed/generate the QR in your Crystal report. Here are some libraries to consider:
BarcodeLib.Crystal.Reports.QRCode- Purpose: Specifically for Crystal Reports, to generate QR codes in .NET Crystal reports.
- Use-case: Good if you want a library that is directly designed for Crystal Reports.
BarcodeLib.Crystal.Reports- More general Crystal Reports barcode library, supports QR Code, Data Matrix, etc.
OnBarcode.Crystal.Reports- A full SDK for barcodes in Crystal Reports, including QR Code, Data Matrix, Code 128, etc.
- Compatible across .NET Standard, .NET Core, and .NET Framework.
BarcodeLib.Barcode- More of a general .NET barcode/QR library. Can generate QR codes, but not Crystal-Reports-specific; you'd generate the image using this library and then embed that image in your Crystal Report.
Neodynamic.SDK.Barcode- A richer barcode SDK, supports QR Code + many other symbologies, and has support for Crystal Reports.
QRCoder- A very simple, open-source library to generate QR codes.
- Use-case: Generate QR images (e.g., as PNG or byte array) in your .NET code, then pass those images to Crystal Reports (e.g., store in a DB or pass via a dataset) and display in the report.
Here we will continue the steps with QRCoder library. If you want to know how to install libraries from NuGet, visit this post "Installing NuGet Packages: A Beginner's Guide".
Generating a QR Code in C#
Here’s a C# example that generates a QR code and stores it in a DataTable for Crystal Reports:using System;
using System.Data;
using System.Drawing;
using System.IO;
using QRCoder;
public DataTable GetQRDataTable(string qrText)
{
DataTable dt = new DataTable();
dt.Columns.Add("QRCode", typeof(byte[]));
dt.Columns.Add("Description", typeof(string));
// Generate QR code
QRCodeGenerator qrGen = new QRCodeGenerator();
QRCodeData qrData = qrGen.CreateQrCode(qrText, QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrData);
Bitmap qrImage = qrCode.GetGraphic(20);
// Convert QR image to byte[]
byte[] qrBytes;
using (MemoryStream ms = new MemoryStream())
{
qrImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
qrBytes = ms.ToArray();
}
// Add row to DataTable
dt.Rows.Add(qrBytes, qrText);
return dt;
}
Explanation
QRCoderproduces a QR code bitmap.- The QR code is converted to a
byte[], which is the format Crystal Reports expects for "image" fields. - The DataTable is later bound to the Crystal Report.
Passing the Dataset to Crystal Reports
using CrystalDecisions.CrystalReports.Engine;
public void LoadReport()
{
var dt = GetQRDataTable("https://your-url-or-data");
ReportDocument rpt = new ReportDocument();
rpt.Load("QRReport.rpt");
rpt.SetDataSource(dt);
crystalReportViewer1.ReportSource = rpt;
}
Designing Crystal Reports to Display the QR Code
- Create a Dataset Schema (.xsd)
- Create a new DataSet in Visual Studio.
- Add a DataTable with a column named
QRCode(type: byte[]) - Save the XSD.
- Add the Dataset to the Report
- Open QRReport.rpt in Crystal Reports.
- Go to Database → Database Expert.
- Add your DataSet (XSD) to the report.
- Save the XSD.
- Insert an Image Field
- Go to Field Explorer → Database Fields.
- Right-click the QRCode field and choose Insert into Report.
- Place it where you want the QR code to appear.
Crystal Reports will automatically detect it as an image at runtime.
Troubleshooting
QR code displays as a red X (broken image)- Ensure the field type in the XSD is byte[]
- Pass the data before calling ReportSource
- Do not store the image as a Base64 string—Crystal cannot decode it
- Set the image object’s properties: Format Object → Picture → Scaling → Fit to frame
Output the image as PNG or BMP only.
qrImage.Save(ms, ImageFormat.Png);
To display a QR code in Crystal Reports, you have two more alternative methods. Below are clear, step-by-step instructions for each.
Use a QR Code Font (Simplest)
Crystal Reports does not generate QR codes natively, but you can use a QR code font such as:- IDAutomation 2D QR-Code Font
- FreeQRCodeFont, etc.
- Install a QR Code font on the computer running Crystal Reports and on the report server (if used).
- In Crystal, create a formula field containing the text you want encoded.
- Example:
"https://example.com?id=" + {Table.Field} - Place the formula on the report.
- Change the font of that field to the QR Code font you installed.
- Preview the report — the text will render as a QR code.
Use Crystal Reports Native Barcode Generator UFL
- Install a QR code UFL (User Function Library):
- Example: IDAutomation UFL for Crystal Reports
- Restart Crystal Reports.
- Create a formula using the UFL function (example):
IDAutomationQRCodeEncoder({Table.Field}) - Insert the formula field into your report.
- Apply the recommended 2D barcode font.
Summary
Displaying a QR code in Crystal Reports is straightforward once you generate the QR code in C# and pass it as an image. With the help of C# libraries like QRCoder, you can embed QR codes in invoices, receipts, ID badges, labels, and any report that needs machine-readable data.
Thanks