Removing existing watermarks is another powerful feature of the GroupDocs.Watermark library. It allows searching and then removing text or image watermarks from a wide range of supported documents. Removing watermarks is possible for some of the supported formats. To learn whether it is available for your format, check Supported formats.
Note
Updating of watermarks is not allowed in evaluation mode. Please set up a license as described in Licensing and evaluation.
Deleting text watermarks
To search and remove text watermarks:
Create an instance of the Watermarker class for a local file or file stream;
Specify the sought-after text of the watermark. 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.
Use the Clear method of the PossibleWatermarkCollection class to remove all found watermarks.
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);// Clear all found watermarkspossibleWatermarks.Clear();// Save documentwatermarker.Save("C:\\Docs\\clean-sample.docx");}
Run the program. All found occurrences of “Contract Draft” in watermarks will be removed.
Deleting image watermarks
To search and remove image watermarks within the document:
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.
(Optionally.) 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.
Use the Clear method of the PossibleWatermarkCollection class to remove all found watermarks.
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);// Clear all found watermarkspossibleWatermarks.Clear();// Save documentwatermarker.Save("C:\\Docs\\clean-sample.docx");}
Run the program. All found occurrences of image watermarks will be deleted.
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.