How to Generate Swiss QR Codes Using Aspose.BarCode for .NET
This article explains how to generate Swiss QR codes (QR-bill) with Aspose.BarCode for .NET in C#. The Swiss QR code is mandatory for digital invoicing and payments in Switzerland, following strict layout and data rules defined by SIX Interbank Clearing.
Real-World Problem
Swiss businesses must include a standardized QR code (QR-bill) on invoices to automate payments and meet legal requirements. The format is regulated, and non-compliance may lead to rejected payments or legal issues.
Solution Overview
Aspose.BarCode for .NET provides a specialized SwissQR encoder to create QR-bill codes according to Swiss standards, including field delimiters and error correction, ready for banking and invoicing workflows.
Prerequisites
Before you start, ensure you have:
- Visual Studio 2019 or later
- .NET 6.0 or later (or .NET Framework 4.6.2+)
- Aspose.BarCode for .NET installed via NuGet
- 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 Swiss QR Code Generator
Prepare Swiss QR code data per QR-bill format. Example:
string swissQrData = "SPC\n0200\n1\nCH9300762011623852957\nS\nRobert Schneider AG\nRue du Lac 1268\n2501\nBiel\nCH\n\n\n3949.75\nCHF\nHans Muster\nBahnhofstrasse 1\n8001\nZurich\nCH\nQRR\n210000000003139471430009017\nInvoice 2025\nEPD";
BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.SwissQR, swissQrData);
Step 3: Customize Swiss QR Layout and Settings
Set ECC level and color for compliance:
generator.Parameters.Barcode.QR.QrErrorLevel = QRErrorLevel.LevelM;
generator.Parameters.Barcode.XDimension.Pixels = 6;
generator.Parameters.Barcode.BarColor = Color.Black;
generator.Parameters.Barcode.BackColor = Color.White;
Step 4: Generate and Save the Swiss QR Code
Export to PNG or other supported formats:
generator.Save("swiss-qr-bill.png", BarCodeImageFormat.Png);
Step 5: Complete Example
using Aspose.BarCode.Generation;
using System.Drawing; // Required for Color
class Program
{
static void Main()
{
string swissQrData = "SPC\n0200\n1\nCH9300762011623852957\nS\nRobert Schneider AG\nRue du Lac 1268\n2501\nBiel\nCH\n\n\n3949.75\nCHF\nHans Muster\nBahnhofstrasse 1\n8001\nZurich\nCH\nQRR\n210000000003139471430009017\nInvoice 2025\nEPD";
BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.SwissQR, swissQrData);
generator.Parameters.Barcode.QR.QrErrorLevel = QRErrorLevel.LevelM;
generator.Parameters.Barcode.XDimension.Pixels = 6;
generator.Parameters.Barcode.BarColor = Color.Black;
generator.Parameters.Barcode.BackColor = Color.White;
generator.Save("swiss-qr-bill.png", BarCodeImageFormat.Png);
// Validate QR-bill with Swiss banking app
}
}
Use Cases and Applications
- Swiss invoices and billing: Legally required QR-bill for electronic and paper invoices
- Banking/payments: Instant data entry for Swiss financial institutions
- Compliance audits: Generate and log QR-bill data for regulatory checks
Common Challenges and Solutions
Challenge 1: Payment rejected by bank? Solution: Validate QR data structure and field lengths, follow SIX QR-bill format strictly.
Challenge 2: QR not readable by apps? Solution: Use Level M error correction, ensure correct DPI, print size, and contrast.
Challenge 3: Data mapping for invoices? Solution: Automate QR-bill data string generation from invoice fields.
Performance Considerations
- Batch-generate Swiss QR codes for invoices
- Use memory streams for integration with ERP or banking platforms
- Test with all major Swiss banking apps
Best Practices
- Validate all output QR codes using official QR-bill validators
- Use sample invoice data for early tests, then automate for production
- Export at 300 DPI for print invoices
- Log all QR-bill data for audit and compliance
Advanced Scenarios
1. Batch Generate Swiss QR Codes for Multiple Invoices
foreach (var invoice in invoices)
{
BarcodeGenerator g = new BarcodeGenerator(EncodeTypes.SwissQR, invoice.QrData);
g.Save($"swissqr_{invoice.Id}.png", BarCodeImageFormat.Png);
}
2. Custom QR Code Appearance
generator.Parameters.Barcode.BarColor = Color.DarkGreen;
generator.Parameters.Barcode.BackColor = Color.WhiteSmoke;
Conclusion
With Aspose.BarCode for .NET, you can create Swiss QR-bill codes for digital invoicing and payments, fully compliant with Swiss banking requirements. See more in the Aspose.BarCode API Reference .