Back to Devexpress

Aztec Code

xtrareports-405177-feature-guide-to-devexpress-reports-use-report-controls-use-bar-codes-aztec-code.md

latest4.4 KB
Original Source

Aztec Code

  • Feb 18, 2026
  • 2 minutes to read

Aztec Code is a matrix code that has the potential to use less space than other matrix barcodes because it does not require a surrounding blank “quiet zone”. Aztec codes are widely used for transport ticketing.

Refer to the following article for more details: Aztec Code.

Add a Bar Code to a Report

To add a barcode to a report, follow these steps:

  1. Drag the XRBarCode item from the DX.25.2: Report Controls tab and drop it onto the report.

  2. Set the XRBarCode control’s Symbology property to Aztec Code (an object of the AztecCodeGenerator type).

  3. Specify common barcode properties and properties specific to Aztec Code.

Specific Properties

AztecCodeGenerator.CompactionModeSpecifies whether text or binary mode should be used to encode the barcode’s data.AztecCodeGenerator.VersionSpecifies the Aztec Code version.AztecCodeGenerator.ErrorCorrectionLevelSpecifies the amount of redundancy built into the bar code to compensate for calculation errors.

Runtime Example

The following code snippet generates an Aztec Code barcode and specifies its properties:

View Example: How to add a bar code to a report

csharp
using System.Collections.Generic;
using System.Drawing.Printing;
using DevExpress.XtraPrinting.BarCode;
using DevExpress.XtraReports.UI;

public XRBarCode CreateAztecCode(string BarCodeText) {
    // Create a barcode control.
    XRBarCode barCode = new XRBarCode();

    // Set the barcode's type to Aztec Code.
    barCode.Symbology = new AztecCodeGenerator();

    // Adjust the barcode's main properties.
    barCode.Text = BarCodeText;
    barCode.Width = 300;
    barCode.Height = 100;

    // Adjust the properties specific to the barcode type.
    ((AztecCodeGenerator)barCode.Symbology).Version = AztecCodeVersion.Version27x27;
    ((AztecCodeGenerator)barCode.Symbology).ErrorCorrectionLevel = AztecCodeErrorCorrectionLevel.Level1;
    ((AztecCodeGenerator)barCode.Symbology).CompactionMode = AztecCodeCompactionMode.Text;

    return barCode;
}
vb
Imports System.Collections.Generic
Imports System.Drawing.Printing
Imports DevExpress.XtraPrinting.BarCode
Imports DevExpress.XtraReports.UI

Public Function CreateAztecCode(ByVal BarCodeText As String) As XRBarCode
    ' Create a barcode control.
    Dim barCode As New XRBarCode()

    ' Set the barcode's type to Aztec Code.
    barCode.Symbology = New AztecCodeGenerator()

    ' Adjust the barcode's main properties.
    barCode.Text = BarCodeText
    barCode.Width = 300
    barCode.Height = 100

    ' Adjust the properties specific to the barcode type.
    CType(barCode.Symbology, AztecCodeGenerator).Version = AztecCodeVersion.Version27x27
    CType(barCode.Symbology, AztecCodeGenerator).ErrorCorrectionLevel = AztecCodeErrorCorrectionLevel.Level1
    CType(barCode.Symbology, AztecCodeGenerator).CompactionMode = AztecCodeCompactionMode.Text

    Return barCode
End Function

The code example below shows how to create a report with an Aztec Code barcode:

csharp
using DevExpress.XtraPrinting.BarCode;
using DevExpress.XtraReports.UI;
//...

var barCode = CreateAztecCode("0123-456789");

var report = new XtraReport() {
    Bands = {
        new DetailBand() {
            Controls = { barCode }
        }
    }
};
vb
Imports DevExpress.XtraPrinting.BarCode
Imports DevExpress.XtraReports.UI
'...

Private barCode = CreateAztecCode("0123-456789")

Dim report As New XtraReport()
Dim band = New DetailBand()
band.Controls.Add(barCode)