manuelbl / SwissQRBill.NET

.NET library for Swiss QR bill payment slips (aka QR-Rechnung)
MIT License
88 stars 33 forks source link
csharp dotnet pdf svg

Swiss QR Bill for .NET

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.

Introduction

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.

QR Bill

More examples can be found in the Wiki

Features

The Swiss QR bill library:

Getting started

  1. Create a new Visual Studio project for .NET Core 3.x (File > New > Project... / Visual C# > .NET Core > Console App (.NET Core))

  2. 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
  1. Add the code:
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) }");
        }
    }
}
  1. Run it

API documentation

See DocFX API Documentation

NuGet packages

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 PDF 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.

Changes effective November 21, 2025

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:

PNG 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:

PDF generation

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.

Code examples

This library comes with multiple code examples:

More information

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.

Other programming languages

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.