Updating QR-code signatures with advanced options

GroupDocs.Signature provides QrCodeSignature class to manipulate qr-code signatures location, size, textual content and encode type over update method of Signature class. This method returns UpdateResult object to analyze if signatures were successfully processed.

Please be aware that update method modifies the same document that was passed to constructor of Signature class. The UpdateResultcontains list of successfully updated signatures and ones that failed. The Barcode signature could be failed to update due to several reasons:

  • if signature object was initialized with constructor by incorrect signature identifier;
  • if signature object was not found;
  • there was an error occurred while updating signature in the document.

Here are the steps to update QR-code signature in the document with GroupDocs.Signature:

Here are the alternative steps to update QR-code signature in the document with GroupDocs.Signature. This approach is based on saved signatures Id after search or sign  methods.

  • Create new instance of Signature class and pass source document path as a constructor parameter;
  • Instantiate one or several  QrCodeSignature objects with signature Id(s) passed to constructor;
  • Call Signature class object update method and pass one or several signatures to it;
  • Analyze UpdateResult result to check whether signatures were updated or not. 

The following table describes changeable properties for QR-code signatures dependent on document type

Document Type / Signature PropertyLeftTopWidthHeightEncodeTypeTextIsSignature
Image(error)(error)(error)(error)(error)(error)(error)
Spreadsheet(tick)(tick)(tick)(tick)(error)(error)(tick)
Pdf(tick)(tick)(tick)(tick)(error)(error)(tick)
Presentation(tick)(tick)(tick)(tick)(error)(error)(tick)
Word Processing(tick)(tick)(tick)(tick)(error)(error)(tick)

This example shows how to update QR-code signature that was found using  search method.

// initialize Signature instance
Signature signature = new Signature("sampleSigned.pdf");
BarcodeSearchOptions options = new BarcodeSearchOptions();
 
List<QrCodeSignature> signatures = signature.search(QrCodeSignature.class, options);
List<BaseSignature> bS = new ArrayList<BaseSignature>();
// adjust signature properties
for (QrCodeSignature temp : signatures)
{
    // apply some condition to adjust signature properties
    temp.setLeft(temp.getLeft() + 100);
    temp.setTop(temp.getTop() + 100);
    temp.setSignature(true);
    bS.add(temp);
}
// update all found signatures
UpdateResult updateResult = signature.update("sampleSigned.pdf",bS);
if (updateResult.getSucceeded().size() == signatures.size())
{
    System.out.print("\nAll signatures were successfully updated!");
}
else
{
    System.out.print("Successfully updated signatures : "+updateResult.getSucceeded().size());
    System.out.print("Not updated signatures : "+updateResult.getFailed().size());
}
System.out.print("List of updated signatures:");
for (BaseSignature temp : updateResult.getSucceeded())
{
    System.out.print("Signature# Id:"+temp.getSignatureId()+", Location: "+temp.getLeft()+"x"+temp.getTop()+". Size: "+temp.getWidth()+"x"+temp.getHeight());
}

Update QR-code signature in document by known signature Identifier

This example shows how to update QR-code signature in the document by known signature Id (that was obtained by  search or sign method previously).

// initialize Signature instance
Signature signature = new Signature("signed.xlsx");
// read from some data source signature Id value
String[] signatureIdList = new String[]
        {
                "1dd21cf3-b904-4da9-9413-1ff1dab51974",
                "b0123987-b0d4-4004-86ec-30ab5c41ac7e"
        };
// create list of Barcode Signature by known SignatureId
List<BaseSignature> signatures = new ArrayList<BaseSignature>();
for (String item : signatureIdList)
{
    QrCodeSignature temp = new QrCodeSignature(item);
    temp.setWidth(150);
    temp.setHeight(150);
    temp.setLeft(200);
    temp.setTop(200);
    signatures.add(temp);
}
// update all found signatures
UpdateResult updateResult = signature.update("signed.xlsx",signatures);
if (updateResult.getSucceeded().size() == signatures.size())
{
    System.out.print("\nAll signatures were successfully updated!");
}
else
{
    System.out.print("Successfully updated signatures : "+updateResult.getSucceeded().size());
    System.out.print("Not updated signatures : "+updateResult.getFailed().size());
}
System.out.print("List of updated signatures:");
for (BaseSignature temp : updateResult.getSucceeded())
{
    System.out.print("Signature# 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.