Updating multiple signatures of different types
Leave feedback
GroupDocs.Signature provides different classes of signatures to manipulate them by changing its properties 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 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;
the signature type is not supported for modification (Digital, Form Field or Metadata signature).
Here are the steps to update multiple signature in the document with GroupDocs.Signature:
Create new instance of Signature class and pass source document path as a constructor parameter;
Instantiate one or several Search options with desired properties;
Call Search method and pass created list of Search Options to obtain list of BaseSignatures;
Select from list BaseSignatures 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.
Update multiple signatures of different types in the document
This example shows how to update signature that was found using Search method.
// initialize Signature instanceusing(Signaturesignature=newSignature("signed.pptx")){// define few search optionsBarcodeSearchOptionsbarcodeOptions=newBarcodeSearchOptions();QrCodeSearchOptionsqrCodeOptions=newQrCodeSearchOptions();// add options to listList<SearchOptions>listOptions=newList<SearchOptions>();listOptions.Add(barcodeOptions);listOptions.Add(qrCodeOptions);// search for signatures in documentSearchResultresult=signature.Search(listOptions);if(result.Signatures.Count>0){Console.WriteLine("\nTrying to update all signatures...");// mark all signatures as actual Signaturesforeach(BaseSignaturebaseSignatureinresult.Signatures){baseSignature.IsSignature=true;}// update all found signaturesUpdateResultupdateResult=signature.Update(result.Signatures);if(updateResult.Succeeded.Count==result.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("\nList of updated signatures:");intnumber=1;foreach(BaseSignaturetempinupdateResult.Succeeded){Console.WriteLine($"Signature #{number++}: Type: {temp.SignatureType} Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}");}}else{Console.WriteLine("No one signature was found.");}}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples: