Sign document with QR-code signature - advanced

GroupDocs.Signature provides QrCodeSignOptions class to specify additional options for QR-code signature with following signature appearance

  • signature alignment
  • margins
  • border and background settings
  • font and colors

Here are the steps to add QR-code signature into document with GroupDocs.Signature:

  • Create new instance of Signature class and pass source document path or stream as a constructor parameter.
  • Instantiate the QrCodeSignOptions object with all required additional options.
  • Call sign method of Signature class instance and pass QrCodeSignOptions to it.
  • Analyze SignResult result to check newly created signatures if needed.

This example shows how to add QR-Code signature to document.

 Signature signature = new Signature("sample.xlsx");
// create QRCode option with predefined QRCode text
QrCodeSignOptions signOptions = new QrCodeSignOptions("12345678");
 
// setup QRCode encoding type
signOptions.setEncodeType(QrCodeTypes.QR);
// set signature position
signOptions.setLeft(100);
signOptions.setTop(100);
 
// set signature alignment
 
// when VerticalAlignment is set the Top coordinate will be ignored.
// Use Margin properties Top, Bottom to provide vertical offset
signOptions.setVerticalAlignment(VerticalAlignment.Top);
 
// when HorizontalAlignment is set the Left coordinate will be ignored.
// Use Margin properties Left, Right to provide horizontal offset
signOptions.setHorizontalAlignment(HorizontalAlignment.Right);
Padding padding = new Padding();
padding.setRight(20);
padding.setTop(20);
signOptions.setMargin(padding);
 
// adjust signature appearance
 
// setup signature border
Border border = new Border();
border.setColor(Color.GREEN);
border.setDashStyle(DashStyle.DashLongDashDot);
border.setWeight(2);
border.setTransparency(0.5);
border.setVisible(true);
signOptions.setBorder(border);
 
// set text color and Font
signOptions.setForeColor(Color.RED);
SignatureFont font = new SignatureFont();
font.setSize(12);
font.setFamilyName("Comic Sans MS");
signOptions.setFont(font);
 
// setup background
Background background = new Background();
background.setColor(Color.GREEN);
background.setTransparency(0.5);
background.setBrush(new LinearGradientBrush(Color.GREEN, Color.DARK_GRAY, 0));
signOptions.setBackground(background);
 
// sign document to file
SignResult signResult = signature.sign("sampleSigned.xlsx", signOptions);
// analyzing result
System.out.print("List of newly created signatures:");
int number = 1;
for(BaseSignature temp : signResult.getSucceeded())
{
    System.out.print("Signature #"+ number++ +": Type: "+temp.getSignatureType()+" Id:"+temp.getSignatureId()+
            ",Location: "+temp.getLeft()+"x"+temp.getTop()+". Size: "+temp.getWidth()+"x"+temp.getHeight());
}

More resources

GitHub Examples 

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

Free Online App 

Along with full-featured .NET library we provide simple, but powerful free Apps.
You are welcome to eSign PDF, Word, Excel, PowerPoint documents with free to use online GroupDocs Signature App. E

© Aspose Pty Ltd 2001-2022. All Rights Reserved.