Clear watermarks

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:

  1. Create an instance of the Watermarker class for a local file or file stream;
  2. 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.
  3. 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.
  4. Use the Clear method of the PossibleWatermarkCollection class to remove all found watermarks.
  5. Call the Save method to store the document in a new location.
using GroupDocs.Watermark;
using GroupDocs.Watermark.Search.SearchCriteria;
using GroupDocs.Watermark.Search;

using (Watermarker watermarker = new Watermarker("C:\\Docs\\watermarked-sample.docx"))
{
    // Search watermark matching a particular text
    TextSearchCriteria searchCriteria = new TextSearchCriteria("Contract Draft", false);
    PossibleWatermarkCollection possibleWatermarks = watermarker.Search(searchCriteria);    
    // Clear all found watermarks
    possibleWatermarks.Clear();
    // Save document
    watermarker.Save("C:\\Docs\\clean-sample.docx");
}

Run the program. All found occurrences of “Contract Draft” in watermarks will be removed. Cleaning text watermarks

Deleting image watermarks

To search and remove image watermarks within the document:

  1. Create an instance of the Watermarker class for a local file or file stream;
  2. Specify the sought-after image of the watermarks. To define criteria use the instance of the ImageSearchCriteria class.
  3. (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.
  4. 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.
  5. Use the Clear method of the PossibleWatermarkCollection class to remove all found watermarks.
  6. Call the Save method to store the document in a new location.
using GroupDocs.Watermark;
using GroupDocs.Watermark.Search.SearchCriteria;
using GroupDocs.Watermark.Search;

using (Watermarker watermarker = new Watermarker("watermarked-sample.docx"))
{
    // Initialize criteria with the image    
    ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria("logo.png");
    //Set maximum allowed difference between images
    imageSearchCriteria.MaxDifference = 0.9;
    PossibleWatermarkCollection possibleWatermarks = watermarker.Search(imageSearchCriteria);
    // Clear all found watermarks
    possibleWatermarks.Clear();
    // Save document
    watermarker.Save("clean-sample.docx");
}

Run the program. All found occurrences of image watermarks will be deleted.

Cleaning image watermarks