Open-source .NET library to generate Swiss QR bills (jointly developed with the Java version).
Try it yourself and create a QR bill. The code for this demonstration (React UI and RESTful service) can be found on GitHub as well.
This library implements version 2.2 and 2.3 of the Swiss Implementation Guidelines QR-bill from November 20, 2023, and Swico Syntax Definition (S1) from November 23, 2018.
The Swiss QR bill is the QR code based payment format that started on 30 June, 2020. The payment slip is sent electronically or presented online in most cases. It can still be printed at the bottom of an invoice or added to the invoice on a separate sheet. The payer scans the QR code with his/her mobile banking app to initiate the payment and then just needs to confirm it.
If the invoicing party adds structured bill information (VAT rates, payment conditions etc.) to the QR bill, the payer can automate the booking in accounts payable. The invoicing party can also automate the accounts receivable processing as the payment includes all relevant data including a reference number. The Swiss QR bill is convenient for the payer and payee.
More examples can be found in the Wiki
The Swiss QR bill library:
System.Drawing
for generating PNG and EMF filesCreate a new Visual Studio project for .NET Core 3.x (File > New > Project... / Visual C# > .NET Core > Console App (.NET Core))
Add the library via NuGet:
Either via Project > Manage NuGet Packages... / Browse / search for qrbill / Install
Or by running a command in the Package Manager Console
Install-Package Codecrete.SwissQRBill.Generator -Version 3.3.0
using Codecrete.SwissQRBill.Generator;
using System;
using System.IO;
namespace Codecrete.SwissQRBill.Examples.Basic
{
class Program
{
static void Main(string[] args)
{
// Setup bill data
Bill bill = new Bill
{
// creditor data
Account = "CH4431999123000889012",
Creditor = new Address
{
Name = "Robert Schneider AG",
Street = "Rue du Lac",
HouseNo = "1268/2/22",
PostalCode = "2501",
Town = "Biel",
CountryCode = "CH"
},
// payment data
Amount = 199.95m,
Currency = "CHF",
// debtor data
Debtor = new Address
{
Name = "Pia-Maria Rutschmann-Schnyder",
Street = "Grosse Marktgasse",
HouseNo = "28",
PostalCode = "9400",
Town = "Rorschach",
CountryCode = "CH"
},
// more payment data
Reference = "210000000003139471430009017",
UnstructuredMessage = "Abonnement für 2020",
// output format
Format = new BillFormat
{
Language = Language.DE,
GraphicsFormat = GraphicsFormat.SVG,
OutputSize = OutputSize.QrBillOnly
}
};
// Generate QR bill
byte[] svg = QRBill.Generate(bill);
// Save generated SVG file
const string path = "qrbill.svg";
File.WriteAllBytes(path, svg);
Console.WriteLine($"QR bill saved at { Path.GetFullPath(path) }");
}
}
}
See DocFX API Documentation
Swiss QR Bill generation is available as three different NuGet packages. They all include the basic QR bill generation for PDF and SVG and only differ with regards to the PNG and EMF generation.
NuGet packages | SVG | PNG | EMF | Platform neutral | Recommendation | |
---|---|---|---|---|---|---|
Codecrete.SwissQRBill.Core | ✓ † | ✓ | – | – | ✓ | Platform-independent core without PNG and EMF generation. |
Codecrete.SwissQRBill.Generator | ✓ † | ✓ | ✓ | – | ✓ | Core plus platform-independent PNG generation (based on SkiaSharp). |
Codecrete.SwissQRBill.Windows | ✓ † | ✓ | ✓ | ✓ | – | Windows specific package including core plus PNG and EMF generation based on System.Drawing.Common |
† See the note below related to PDF generation with the extended Latin character set.
On November 21, 2025, the QR bill specification 2.3 and further changes in the Swiss payment standards will become effective. The library is ready for these changes:
bill.CharacterSet = SpsCharacterSet.ExtendedLatin
. Do not use it before November 21, 2025. Also see the below regaring PDF generation.PNG generation requires a raster graphics library. Starting with .NET 6, the System.Drawing classes have become a Windows-only technology and standard .NET no longer supports raster graphics out-of-the-box. With this library, you have several options:
To generate QR bills as PDF files, this library uses its own, minimal PDF generator that requires no further dependencies and comes with the same permissive license as the rest of this library.
The built-in PDF generator does not support font embedding and is thus restricted to the standard 14 PDF fonts, which in turn are restricted to the WinANSI character set. This is sufficient to generate QR bills using the original character set (a subset of Latin-1). However, it is insufficient to generate QR bills using the extended Latin character set (allowed from November 21, 2025). If the extended character set is to be used, use one of the below options.
The libary can be integrated with iText or PDFsharp. See the example projects for more information:
These examples also support adding a QR bill to an existing PDF document.
This library comes with multiple code examples:
Basic: A basic example showing how to generate a QR bill.
WindowsForms: An extensive example showing how to use this library in a Windows Forms application (display of QR bills on the screen, printing, working with the clipboard).
WindowsPresentationFoundation: An example for Windows Presentation Foundation (WPF) applications. It shows how to display and print QR bills.
WinUI: An example for WinUI applications. It shows how to display and print QR bills.
MicrosoftWordAddIn: Implements an add-in for Microsoft Word capable of inserting a QR bill as a resolution independent EMF graphics. As C# add-ins use the Microsoft Word Interop interface, this example is also relevant for other software interacting with Microsoft Word.
iText: Example showing how to generate PDFs using the iText library, including how to add a QR bill to an existing PDF document.
PDFsharp: Example showing how to generate PDFs using the PDFsharp library, including how to add a QR bill to an existing PDF document.
This library is the .NET version of Swiss QR Bill. There is also a Java version with the same features. More information about both libraries can be found in the Wiki.
If you are looking for a library for yet another programming language or for a library with professional services, you might want to check out Services & Tools on MoneyToday.ch.