This example will walk through a typical QR bill generation into a PDF. It will not show all available options.

Read the Basics document first to understand the terms of a QR bill.

Generating the QR bill

This code will generate the payment part of an example invoice and store it in paymentPart.pdf.

import ch.codeblock.qrinvoice.FontFamily;
import ch.codeblock.qrinvoice.OutputFormat;
import ch.codeblock.qrinvoice.PageSize;
import ch.codeblock.qrinvoice.QrInvoicePaymentPartReceiptCreator;
import ch.codeblock.qrinvoice.model.QrInvoice;
import ch.codeblock.qrinvoice.model.builder.QrInvoiceBuilder;
import ch.codeblock.qrinvoice.model.validation.ValidationException;
import ch.codeblock.qrinvoice.model.validation.ValidationResult;
import ch.codeblock.qrinvoice.output.PaymentPartReceipt;

import java.util.Locale;

public class QrInvoiceBuilderTypicalExample {
    public static void main(String[] args) {
        // 1. Build the invoice object
        QrInvoice qrInvoice = buildInvoice();

        // 2. Generate the payment part as PDF
        byte[] qrBillPdf = createQrBill(qrInvoice);

        // 3. Write the PDF

    private static QrInvoice buildInvoice() {
        QrInvoice qrInvoice = null;

        try {
            qrInvoice = QrInvoiceBuilder
                    .creditorIBAN("CH44 3199 9123 0008 8901 2")
                    .paymentAmountInformation(p -> p
                    .creditor(c -> c
                            .name("Robert Schneider AG")
                            .streetName("Rue du Lac")
                    .ultimateDebtor(d -> d
                            .combinedAddress() // Unstructured method to provide a postal address
                            .name("Pia-Maria Rutschmann-Schnyder")
                            .addressLine1("Grosse Marktgasse 28")
                            .addressLine2("9400 Rorschach")
                    .paymentReference(r -> r
                    .additionalInformation(a -> a
                            .unstructuredMessage("Instruction of 03.04.2019") // Max. 140 characters, no linebreaks
        } catch (ValidationException validationException) {
            final ValidationResult validationResult = validationException.getValidationResult();


        return qrInvoice;

    private static byte[] createQrBill(QrInvoice qrInvoice) {
        final PaymentPartReceipt paymentPartReceipt = QrInvoicePaymentPartReceiptCreator
                .pageSize(PageSize.A4) // Use DIN_LANG to generate a A6 page with the payment part only
                .fontFamily(FontFamily.LIBERATION_SANS) // or HELVETICA, ARIAL
                .locale(Locale.GERMAN) // Supported: GERMAN, FRENCH, ENGLISH, ITALIAN

        // the resulting byte array contains the payment part & receipt as PDF
        return paymentPartReceipt.getData();

    private static void writePdf(byte[] qrBillPdf) {
        try (FileOutputStream stream = new FileOutputStream("paymentPart.pdf")) {
        } catch (Exception e) {

Combining the Payment Part with your invoice

The QrPdfMerger library provides some utility methods to handle PDF documents.

Assuming the top part of your QR bill is stored in invoice.pdf and the payment part in paymentPart.pdf, the following code will combine those PDFs together into qrBill.pdf:

import ch.codeblock.qrinvoice.pdf.QrPdfMerger;

import java.nio.file.Files;
import java.nio.file.Paths;

public class CombinePdfs {
    public static void main(String[] args) {
        try {
            // 1. Read in invoice part
            byte[] invoice = Files.readAllBytes(Paths.get("invoice.pdf"));

            // 2. Read in payment part (Generated by
            byte[] paymentPart = Files.readAllBytes(Paths.get("paymentPart.pdf"));

            // 3. Merge files
            byte[] qrBill = QrPdfMerger.mergePdfs(paymentPart, invoice);

            // 4. Write merged QR bill
            FileOutputStream qrBillFile = new FileOutputStream("qrBill.pdf");

        } catch (Exception e) {