Updating QR-code signatures with advanced options
Leave feedback
On this page
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 UpdateResult contains 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:
Create new instance of Signature class and pass source document path as a constructor parameter;
Select from list QrCodeSignature object(s) that should be updated;
Call Signature object Update method and pass one or several signatures to it.
Analyze UpdateResult result to check whether signatures were updated or not.
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 Property
Left
Top
Width
Height
EncodeType
Text
IsSignature
Image
Spreadsheet
Pdf
Presentation
Word Processing
Update QR-code signature in the document after Search
This example shows how to update QR-code signature that was found using Search method.
// initialize Signature instanceusing(Signaturesignature=newSignature("sampleSigned.pdf")){QrCodeSearchOptionsoptions=newQrCodeSearchOptions();List<QrCodeSignature>signatures=signature.Search<QrCodeSignature>(options);// adjust signature propertiesforeach(QrCodeSignaturetempinsignatures){// apply some condition to adjust signature propertiesif(temp.Text=="Test1"){temp.Left=temp.Left+10;temp.Top=temp.Top+10;temp.IsSignature=false;}else{temp.IsSignature=true;}}// update all found signaturesUpdateResultupdateResult=signature.Update(signatures.ConvertAll(p=>(BaseSignature)p));if(updateResult.Succeeded.Count==signatures.Count){Console.WriteLine("\nAll signatures were successfully updated!");}else{Console.WriteLine($"Successfully updated signatures : {updateResult.Succeeded.Count}");Console.WriteLine($"Not updated signatures : {updateResult.Failed.Count}");}Console.WriteLine("List of updated signatures:");foreach(BaseSignaturetempinupdateResult.Succeeded){Console.WriteLine($"Signature# Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}");}}
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 instanceusing(Signaturesignature=newSignature("signed.xlsx")){// read from some data source signature Id valuestring[]signatureIdList=newstring[]{"1dd21cf3-b904-4da9-9413-1ff1dab51974","9e386726-a773-4971-b2fc-eaadfce65ffd"};// create list of QR-code Signature by known SignatureIdList<BaseSignature>signatures=newList<BaseSignature>();signatureIdList.ToList().ForEach(p=>signatures.Add(newQrCodeSignature(p)));// update all found signaturesUpdateResultupdateResult=signature.Update(signatures);if(updateResult.Succeeded.Count==signatures.Count){Console.WriteLine("All signatures were successfully updated!");}else{Console.WriteLine($"Successfully updated signatures : {updateResult.Succeeded.Count}");Console.WriteLine($"Not updated signatures : {updateResult.Failed.Count}");}Console.WriteLine("List of updated signatures:");foreach(BaseSignaturetempinupdateResult.Succeeded){Console.WriteLine($"Signature# Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}");}}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples: