The GroupDocs.Watermark library is also capable of searching the document for any existing text or image watermarks. These can be watermarks added by any third-party tool, not only by GroupDocs.Watermark. Searching watermarks is possible for some of the supported formats. To learn whether it is available for your format, check Supported formats.
Once found you can update those watermarks.
Note
Updating of watermarks is not allowed in evaluation mode. Please set up a license as described in Licensing and evaluation.
Updating text watermarks
To search and update text watermarks:
Create an instance of the Watermarker class for a local file or file stream;
Specify the sought-after text of the watermarks. To define criteria use the instance of the TextSearchCriteria class. In this example, we will search for a particular string match.
Call the Search method of the Watermarker class to perform the search and obtain a collection of all possible watermarks that meet the search criteria.
Iterate through the collection of possible watermarks and update the found text occurrences using the Text property.
Call the Save method to store the document in a new location.
usingGroupDocs.Watermark;usingGroupDocs.Watermark.Search.SearchCriteria;usingGroupDocs.Watermark.Search;using(Watermarkerwatermarker=newWatermarker("C:\\Docs\\watermarked-sample.docx")){// Search watermark matching a particular textTextSearchCriteriasearchCriteria=newTextSearchCriteria("Contract Draft",false);PossibleWatermarkCollectionpossibleWatermarks=watermarker.Search(searchCriteria);Console.WriteLine("Found {0} possible watermark(s).",possibleWatermarks.Count);foreach(PossibleWatermarkwatermarkinpossibleWatermarks){try{// Update textwatermark.Text="Contract is no longer valid";}catch(Exceptione){// Found entity may not support text editing// Passed argument can have inappropriate value// Process such cases here}}// Save documentwatermarker.Save("C:\\Docs\\updated-sample.docx");}
Run the program. All found occurrences of “Contract Draft” in watermarks will be changed to “Contract is no longer valid”.
What’s next
Text search capabilities of GroupDocs.Watermark are not limited by simple text matches. To learn how to search using regular expressions, or search the watermarks on the basis of some particular text formatting, or update the formatting of found text, see the Searching watermarks and Modifying found watermark properties articles of the “Advanced usage” section.
Updating image watermarks
To search and update text watermarks:
Create an instance of the Watermarker class for a local file or file stream;
Specify the sought-after image of the watermarks. To define criteria use the instance of the ImageSearchCriteria class.
Specify the maximum allowed difference between the images using the MaxDifference property. Too strict threshold may fail to detect all needed images, while a very lenient threshold could match dissimilar images.
Call the Search method of the Watermarker class to perform the search and obtain a collection of all possible watermarks that meet the search criteria.
Iterate through the collection of possible watermarks and update the found image occurrences using the ImageData property.
Call the Save method to store the document in a new location.
usingGroupDocs.Watermark;usingGroupDocs.Watermark.Search.SearchCriteria;usingGroupDocs.Watermark.Search;using(Watermarkerwatermarker=newWatermarker("C:\\Docs\\watermarked-sample.docx")){// Initialize criteria with the image ImageSearchCriteriaimageSearchCriteria=newImageDctHashSearchCriteria("C:\\Docs\\logo.png");//Set maximum allowed difference between imagesimageSearchCriteria.MaxDifference=0.9;PossibleWatermarkCollectionpossibleWatermarks=watermarker.Search(imageSearchCriteria);Console.WriteLine("Found {0} possible watermark(s).",possibleWatermarks.Count);// Read new watermark imagebyte[]imageData=File.ReadAllBytes("C:\\Docs\\new-logo.png");foreach(PossibleWatermarkwatermarkinpossibleWatermarks){try{// Replace imagewatermark.ImageData=imageData;}catch(Exceptione){// Found entity may not support text editing// Passed argument can have inappropriate value// Process such cases here}}// Save documentwatermarker.Save("C:\\Docs\\updated-sample.docx");}
Run the program. All found occurrences of image watermarks will be updated.
What’s next
Searching by images is a way more complex operation that may require finding an appropriate difference threshold or even using other image comparison algorithms. GroupDocs.Watermark offers several image search criteria algorithms. To learn more about them, see the Searching watermarks article of the “Advanced usage” section.
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.