How to Generate Aztec Codes Using Aspose.BarCode for .NET

How to Generate Aztec Codes Using Aspose.BarCode for .NET

This article explains how to generate Aztec codes with Aspose.BarCode for .NET in C#. Aztec is a robust 2D barcode used in mobile ticketing, transport, secure payments, and smart cards due to its quick readability and error correction.

Real-World Problem

Aztec codes are required for many digital and printed tickets, especially in public transportation and airline boarding passes. Developers need reliable, configurable, and batch-friendly ways to generate Aztec codes in .NET applications.

Solution Overview

Aspose.BarCode for .NET enables the generation of Aztec codes with adjustable size, layers, error correction, and color—ready for digital or print distribution in secure and high-volume workflows.


Prerequisites

Before you start, ensure you have:

  1. Visual Studio 2019 or later
  2. .NET 6.0 or later (or .NET Framework 4.6.2+)
  3. Aspose.BarCode for .NET installed via NuGet
  4. Basic knowledge of C#
PM> Install-Package Aspose.BarCode

Step-by-Step Implementation

Step 1: Install and Import Aspose.BarCode

Install the NuGet package and import the required namespaces:

using Aspose.BarCode.Generation;

Step 2: Create the Aztec Code Generator

Instantiate the generator for Aztec codes:

BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Aztec, "TICKET2025-BOARDING");

Step 3: Customize Aztec Code Settings

Configure layers, ECC, and other options:

// Set number of layers (Auto or specific 1-32)
generator.Parameters.Barcode.Aztec.AztecLayers = AztecSymbolMode.Auto;
// Set error correction percent (default: 23%)
generator.Parameters.Barcode.Aztec.AztecErrorLevel = 33;
// Set module (pixel) size
generator.Parameters.Barcode.XDimension.Pixels = 6;
// Optional: Set foreground and background color
generator.Parameters.Barcode.BarColor = Color.Black;
generator.Parameters.Barcode.BackColor = Color.White;

Step 4: Generate and Save the Aztec Code

Export the code to PNG, JPEG, or any supported format:

generator.Save("aztec-code.png", BarCodeImageFormat.Png);

Step 5: Complete Example

using Aspose.BarCode.Generation;
using System.Drawing; // Required for Color

class Program
{
    static void Main()
    {
        // Create Aztec generator for a ticket
        BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Aztec, "TICKET2025-BOARDING");
        generator.Parameters.Barcode.Aztec.AztecLayers = AztecSymbolMode.Auto;
        generator.Parameters.Barcode.Aztec.AztecErrorLevel = 33; // 33% error correction
        generator.Parameters.Barcode.XDimension.Pixels = 6;
        generator.Parameters.Barcode.BarColor = Color.Black;
        generator.Parameters.Barcode.BackColor = Color.White;
        generator.Save("aztec-code.png", BarCodeImageFormat.Png);
        // Test with a mobile scanner
    }
} 

Use Cases and Applications

  • Mobile and transport tickets: Subway, airline, or event entry
  • Payment tokens: Secure payment/transaction codes
  • Identity/Smart cards: Secure personal information encoding

Common Challenges and Solutions

Challenge 1: Aztec code not scanning? Solution: Increase error correction, verify contrast and size, test on intended devices.

Challenge 2: Need higher security? Solution: Use maximum ECC (up to 95%), keep code text short, avoid data redundancy.

Challenge 3: Data too long for one code? Solution: Split across multiple codes, or switch to PDF417 for very large payloads.


Performance Considerations

  • Batch generate Aztec codes for ticketing or mobile apps
  • Use memory streams for high-volume in-memory export
  • Adjust layers and ECC for scan reliability

Best Practices

  1. Use Auto mode for layers unless specific print/size required
  2. Test output on mobile and handheld devices
  3. Export to PNG for best print/display quality
  4. Document all code text and ECC settings for traceability

Advanced Scenarios

1. Batch Generate Aztec Codes

foreach (var item in tickets)
{
    BarcodeGenerator g = new BarcodeGenerator(EncodeTypes.Aztec, item.CodeText);
    g.Save($"aztec_{item.Id}.png", BarCodeImageFormat.Png);
}

2. Set Specific Number of Layers

generator.Parameters.Barcode.Aztec.AztecLayers = AztecSymbolMode.Layers16;

Conclusion

With Aspose.BarCode for .NET, you can generate Aztec codes for transport, mobile, and secure workflows—customized for reliability and speed. See more options in the Aspose.BarCode API Reference .

 English