Searching for document signatures excluding external components
Leave feedback
GroupDocs.Signature provides boolean property setSkipExternal 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 20.3 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 setSignature flag will be set as true. setSignature 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 searchwithsetSkipExternal property set to false (this is default value) and update setSignature 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 setSignature = false property,in this case setSkipExternal field will allow search method to skip this signature;
Signatures that were added before 20.3 are treated as non signatures because information about them are not yet stored in the document. Setting setSkipExternal flag to true will exclude these signatures from Searchresult.
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.
Following example demonstrates usage of setSkipExternal property for excluding non actual signatures from search result
Using SearchOptions SkipExternal property to exclude non actual signatures from search
Signaturesignature=newSignature("sample_signed.pdf");TextSearchOptionsoptions=newTextSearchOptions();options.setSkipExternal(true);options.setAllPages(false);// search for text signatures in document
List<TextSignature>signatures=signature.search(TextSignature.class,options);System.out.print("\nSource document contains following text signature(s).");// enumerate all signature for output
//foreach to while statements conversion
try{for(TextSignaturesign:signatures){if(sign!=null){System.out.print("Found Text signature at page "+sign.getPageNumber()+" with type ["+sign.getSignatureImplementation()+"] and text '"+sign.getText()+"'.");System.out.print("Location at "+sign.getLeft()+"-"+sign.getTop()+". Size is "+sign.getWidth()+"x"+sign.getHeight()+".");}}}catch(Exceptionex){System.out.print("System Exception: "+ex.getMessage());}
Updating signatures from GroupDocs.Signature 20.3 and below
Following examples shows the way to mark signatures in document as actual signatures (setSignature = true)
How to mark signatures in document as actual signatures
// initialize Signature instance
Signaturesignature=newSignature("sample_signed.pdf");// define few search options
BarcodeSearchOptionsbarcodeOptions=newBarcodeSearchOptions();QrCodeSearchOptionsqrCodeOptions=newQrCodeSearchOptions();// add options to list
List<SearchOptions>listOptions=newArrayList<SearchOptions>();listOptions.add(barcodeOptions);listOptions.add(qrCodeOptions);// search for signatures in document
SearchResultresult=signature.search(listOptions);if(result.getSignatures().size()>0){System.out.print("\nTrying to update all signatures...");// mark all signatures as actual Signatures
for(BaseSignaturebaseSignature:result.getSignatures()){baseSignature.setSignature(true);}// update all found signatures
UpdateResultupdateResult=signature.update(outputFilePath,result.getSignatures());if(updateResult.getSucceeded().size()==result.getSignatures().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("\nList of updated signatures:");intnumber=1;for(BaseSignaturetemp:updateResult.getSucceeded()){System.out.print("Signature #"+number+++": Type: "+temp.getSignatureType()+" Id:"+temp.getSignatureId()+", Location: "+temp.getLeft()+"x"+temp.getTop()+". Size: "+temp.getWidth()+"x"+temp.getHeight());}}else{System.out.print("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:
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.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.