Sign document with Swiss QR Barcode signature

GroupDocs.Signature provides SwissQR class to create Swiss QR. The Swiss QR Barcode is used mostly in the QR-bill, which is a document designed to replace the payment slips and currently used in payment transactions in Switzerland.

Here are the steps how to add Swiss QR signature into document with GroupDocs.Signature:

  • Create new instance of Signature class and pass source document path as a constructor parameter.
  • Instantiate the SwissQR object with all required additional options. Creditor and debtor addresses are SwissAddress objects.
  • Instantiate the QrCodeSignOptions object with all required additional options and pass the SwissQR object to its setData method.
  • Call the sign method of the Signature class instance and pass QrCodeSignOptions to it.
  • Analyze the SignResult result to check newly created signatures if needed.
Signature signature = new Signature("sample.pdf");
try {
    // creditor address
    SwissAddress creditor = new SwissAddress();
    creditor.setName("Muster & Söhne");
    creditor.setStreet("Musterstrasse");
    creditor.setHouseNo("12b");
    creditor.setPostalCode("8200");
    creditor.setTown("Zürich");
    creditor.setCountryCode("CH");

    // debtor address
    SwissAddress debtor = new SwissAddress();
    debtor.setName("Muster AG");
    debtor.setStreet("Musterstrasse");
    debtor.setHouseNo("1");
    debtor.setPostalCode("3030");
    debtor.setTown("Bern");
    debtor.setCountryCode("CH");

    // create SwissQR data object
    SwissQR swissQR = new SwissQR();
    swissQR.setAccount("CH4431999123000889012");
    swissQR.setAmount(1000.25);
    swissQR.setCurrency("CHF");
    swissQR.setReference("210000000003139471430009017");
    swissQR.setCreditor(creditor);
    swissQR.setDebtor(debtor);

    // create options
    QrCodeSignOptions options = new QrCodeSignOptions();
    options.setEncodeType(QrCodeTypes.QR);
    options.setLeft(100);
    options.setTop(100);
    // setup Data property to SwissQR instance
    options.setData(swissQR);

    // sign document to file
    SignResult signResult = signature.sign("signed.pdf", options);

    // analyzing result
    System.out.println("List of newly created signatures:");
    int number = 1;
    for (BaseSignature temp : signResult.getSucceeded()) {
        System.out.println("Signature #" + number++ + ": Type: " + temp.getSignatureType()
                + " Id:" + temp.getSignatureId()
                + ", Location: " + temp.getLeft() + "x" + temp.getTop()
                + ". Size: " + temp.getWidth() + "x" + temp.getHeight());
    }
} finally {
    signature.dispose();
}

More resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online Apps

Along with the full-featured Java library, we provide simple but powerful free online apps.

To generate QR codes and/or sign your files with QR codes for free, you can use the QR Code Generator online app.

To sign PDF, Word, Excel, PowerPoint, and other documents you can use the other online apps from the GroupDocs.Signature App Product Family.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.