Searching for document signatures excluding external components
Leave feedback
On this page
GroupDocs.Signature provides boolean property SkipExternal of SearchOptions class to specify if searching process should exclude external signatures (external signatures are the signatures that were added with an 3rd party software and not with GroupDocs.Signature).
Since 19.12 version every time when document is being signed information about document signatures are stored in document’s metadata. Which means that all created signatures by GroupDocs.Signature can be distinguished from an actual document content and IsSignature flag will be set as true. IsSignature property specifies if document component (text/image/barcode/qr-code) is the actual signature or element of document content.
In order to convert signatures added by 3rd party software or by previous version of GroupDocs.Signature, just run Search withSkipExternal property set to false (this is default value) and update IsSignature for each signature returned by the search result.
There are few ways to manipulate with document signature search results:
If signature is no longer required it can be removed from the document by Delete method;
Signature could be marked as document native content by setting up IsSignature = false property,in this case SkipExternal field will allow Search method to skip this signature;
Signatures that were added before 19.12 are treated as non signatures because information about them are not yet stored in the document. Setting SkipExternal flag to true will exclude these signatures from Search result.
Here are the steps to search for signatures and exclude external components of the document with GroupDocs.Signature:
Create new instance of Signature class and pass source document path as a constructor parameter.
Instantiate the SearchOptions object according to your requirements and specify SkipExternal to true
Following example demonstrates usage of SkipExternal property for excluding non actual signatures from search result
Using SearchOptions SkipExternal property to exclude non actual signatures from search
using(Signaturesignature=newSignature("sample_signed.pdf")){TextSearchOptionsoptions=newTextSearchOptions(){// specify SkipExternal value to exclude non signature objects from Search resultSkipExternal=true,// specify search on all pagesAllPages=false};// search for text signatures in documentList<TextSignature>signatures=signature.Search<TextSignature>(options);Console.WriteLine("\nSource document contains following text signature(s).");// enumerate all signature for outputforeach(TextSignaturetextSignatureinsignatures){if(textSignature!=null){Console.WriteLine($"Found Text signature at page {textSignature.PageNumber} with type [{textSignature.SignatureImplementation}] and text '{textSignature.Text}'.");Console.WriteLine($"Location at {textSignature.Left}-{textSignature.Top}. Size is {textSignature.Width}x{textSignature.Height}.");}}}
Updating signatures from GroupDocs.Signature 19.11 and below
Following examples shows the way to mark signatures in document as actual signatures (IsSignature = true)
How to mark signatures in document as actual signatures
// initialize Signature instanceusing(Signaturesignature=newSignature("sample_signed.pdf")){// define search options to select required signatures om the documentBarcodeSearchOptionsbarcodeOptions=newBarcodeSearchOptions();QrCodeSearchOptionsqrCodeOptions=newQrCodeSearchOptions();TextSearchOptionstextOptions=newTextSearchOptions();// add options to listList<SearchOptions>listOptions=newList<SearchOptions>();listOptions.Add(barcodeOptions);listOptions.Add(qrCodeOptions);listOptions.Add(textOptions);// 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: