This example shows how to create the payment part & receipt (the "payment slip"), which contains the Swiss QR Code as well as the same information as text output. The payment part & receipt is created as a DIN Lang (width: 210mm / height: 105mm) document, which can be placed on a A5 or A4 document positioned at the bottom.

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.output.PaymentPartReceipt;

import java.util.Locale;

// ...

final QrInvoice qrInvoice = // create using QrInvoiceBuilder;

final PaymentPartReceipt paymentPartReceipt = QrInvoicePaymentPartReceiptCreator
    .create()
    .qrInvoice(qrInvoice)
    .outputFormat(OutputFormat.PDF)
    .pageSize(PageSize.DIN_LANG)
    .fontFamily(FontFamily.LIBERATION_SANS) // or HELVETICA, ARIAL
    .locale(Locale.GERMAN)
    .createPaymentPartReceipt();

// the resulting byte array contains the payment part & receipt as PDF
final byte[] paymentPartReceiptPdf = paymentPartReceipt.getData();

// meta data for the chosen OutputFormat for convenience
final String mimeType = paymentPartReceipt.getOutputFormat().getMimeType();
final String fileExtension = paymentPartReceipt.getOutputFormat().getFileExtension();

This will generate a PDF containing a payment part & receipt.

Payment Part & Receipt

If you wish to generate a full A4 page with a blank header, set the pageSize to PageSize.A4.

Boundary line and perforation options

The Swiss Implementation Guidelines QR-bill version 2.0 states in chapter 3.1 - The basics

If the payment part with receipt is integrated in a QR-bill in paper form, there must be a perforation between the bill details and the payment part and receipt.

There should be a perforation between the payment part and the receipt, if the QRbill is generated on paper.

and in chapter 3.7 - Notes about the QR-bill in PDF format:

If the QR-bill with payment part and receipt or the separate payment part with receipt are generated as a PDF document and sent electronically, the A6 format of the payment part and the receipt on the left must be indicated by lines. Each of these lines must bear the scissors symbol "✂" or alternatively the instruction "Separate before paying in" above the line (outside the payment part). This indicates to the debtor that he or she must neatly separate the payment part and receipt if they want to forward the QR-bill to their financial institution by post for payment, or settle it at the post office counter (branches or branches of partner organisations).

Summarized this means there are the following options:

  1. When printed (paper form), paper has to be perforated, no boundary lines necessary

  2. When produced as PDF, boundary lines are necessary

    1. with scissors as indicators

    2. with textual instruction above the payment part

QrInvoicePaymentPartReceiptCreator
. // as in the example at the beginning of the page
.withoutBoundaryLines()
.createPaymentPartReceipt();
QrInvoicePaymentPartReceiptCreator
. // as in the example at the beginning of the page
.withBoundaryLines()
.withScissors()
.createPaymentPartReceipt();
QrInvoicePaymentPartReceiptCreator
. // as in the example at the beginning of the page
.withBoundaryLines()
.withoutScissors()
.withSeparationText()
.createPaymentPartReceipt();

Printer margins

According to the specifications, QR-bills have a safety margin of 5mm on each page border. Some printers however have trouble printing this close to the border. Scaling down the page content might decrease the scannability of the QR code. Therefore, the QR-bill can be customized in two ways: Boundary lines with margins and additional print margins.

Boundary lines with margins

In addition to the option .withBoundaryLines(), you can create boundary lines with safety margins by setting the option .withBoundaryLinesWithMargins().

Or set the option directly with .boundaryLines(BoundaryLines.ENABLED…​).

Boundary lines enabled to full extend
Figure 1. BoundaryLines.ENABLED
Boundary lines enabled with margins
Figure 2. BoundaryLines.ENABLED_WITH_MARGINS
Boundary lines disabled
Figure 3. BoundaryLines.NONE

Additional print margin

Setting .withAdditionalPrintMargin() (Or .additionalPrintMargin(true)) will increase the safety margin from 5mm to 6mm.