Deleting multiple signatures of different types
Leave feedback
GroupDocs.Signature provides different classes of signatures to manipulate and delete them from the documents over Delete method.
Please be aware that Delete method modifies the same document that was passed to constructor of Signature class. This method returns DeleteResult object that contains list of successfully updated signatures and ones that failed. The signature could be failed to delete 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 deleting signature in the document;
the signature type is not supported for deletion for current version (for version 19.12 these signatures are Digital, Form Field or Metadata signature).
Here are the steps to delete 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 deleted;
Call Signature object Delete method and pass one or several signatures to it.
Analyze DeleteResult result to check whether signatures were updated or not.
Delete multiple signatures in the document
This example shows how to delete multiple signatures that was found using Search method.
// initialize Signature instanceusing(Signaturesignature=newSignature("signed.docx")){// 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("Trying to delete signatures...");List<BaseSignature>signaturesToDelete=newList<BaseSignature>();// collect image signatures to deleteforeach(BaseSignaturetempinresult.Signatures){if(temp.SignatureType==SignatureType.Image){signaturesToDelete.Add(temp);}}// delete signaturesDeleteResultdeleteResult=signature.Delete(signaturesToDelete);if(deleteResult.Succeeded.Count==signaturesToDelete.Count){Console.WriteLine("All signatures were successfully deleted!");}else{Console.WriteLine($"Successfully deleted signatures : {deleteResult.Succeeded.Count}");Console.WriteLine($"Not deleted signatures : {deleteResult.Failed.Count}");}Console.WriteLine("List of deleted signatures:");foreach(BaseSignaturetempindeleteResult.Succeeded){Console.WriteLine($"Signature# 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: