Skip to end of metadata
Go to start of metadata
Contents Summary

The code samples in this article use some of the methods defined in Working with Common Utilities.

Searching Possible Watermarks 

GroupDocs.Watermark API allows you to search the possible watermarks placed in any document. You can also search the watermarks that are added using some third-party tool. The API provides FindWatermarks method to search watermarks in a whole document or in any part of the document. Following code snippet shows how to find and get all possible watermarks in a document.

Search Criteria

Usually, large documents may contain too many objects which can be considered as watermarks. Parameterless overload of FindWatermarks method returns only some of them, e.g. backgrounds or floating objects which could have been added during document post-processing. You can use search criteria to find objects with some specific parameters.

Text Search Criteria

Following code snippet shows how to search for the watermarks that meet a particular text criterion.

Regular expressions are also supported by TextSearchCriteria. The below sample code uses a regular expression to search for watermarks.

What happens when the user is passing TextSearchCriteria instance to the method?
1. It searches fragments of document's main text which match regular expression (or contain exact search string)
2. It checks text of other objects (shapes, XObjects, annotations etc.) if they match regular expression (or contain exact search string)

Search in the main text of a document is performed only if you pass TextSearchCriteria instance to FindWatermarks method.

Image Search Criteria

Sometimes a document can contain image watermarks, and it's necessary to find them using sample picture. For example, you may want to find all possible image watermarks that are similar to a company logo. Following sample code searches for image watermarks that resemble with a particular image.


MaxDifference property is used to set maximum allowed difference between sample image and possible watermark. The value should be between 0 and 1. The value 0 means that only identical images will be found.

Using of ImageDctHashSearchCriteria is the most efficient way to find image watermark by a sample. This criterion uses DCT (Discrete Cosine Transform) based perceptual hash for image similarity comparison. But there are other image search criteria that are based on other algorithms:

  • ImageColorHistogramSearchCriteria uses image color histograms for calculating image similarity. This criterion is invariant to rotation, scaling, and translation of the image.
  • ImageThumbnailSearchCriteria uses image binarized thumbnail for calculating image similarity. This criterion is invariant to rotation, scaling and insignificant changes of the color palette.

Combined Search Criteria

GroupDocs.Watermark API also allows you to search watermarks by a combination of different search criteria. Following sample code shows how to search watermark with the combination of different search criteria.

For video tutorial, watch Searching Watermark on YouTube.

Text Formatting Search Criteria

GroupDocs.Watermark also enables you to search the watermarks on the basis of some particular text formatting. You can provide a search criterion containing font name, size, color etc and the API will find the watermarks with matching properties. Following code snippet shows how to search watermark with a particular text formatting.


Searching Watermarks in Particular Objects

This feature is supported from version 17.8.0.

This feature allows you to specify which objects should be included in watermark search. Restricting searchable objects, you can significantly increase search performance. Following sample code shows how to set searchable objects globally (for all documents that will be created after that).


You can also set searchable objects for a particular document instance as shown in the sample code below.


Searching Text Watermark Skipping Unreadable Characters

This feature is supported from version 18.8.

This feature allows finding text watermark even if it contains unreadable characters between the letters. The following code sample shows how to skip unreadable characters when searching for the watermark.

Removing Watermark

GroupDocs.Watermark API enables you to easily find and remove a particular watermark from a document. Following code serves this purpose.

For the video tutorial, watch Removing Watermark on YouTube.

Replacing Text and Image in Found Watermarks

This feature is supported by version 18.3 and greater.

GroupDocs.Watermark also allows you to replace text and image in the found possible watermarks. Following sections will show you how to replace text and image of a found watermark.

Replacing Text

To replace text of the found watermarks, loop through the possible watermarks in the watermark collection and replace Text property as shown in the following code sample.

Replacing Text with Formatting

You can also replace the watermark's text with formatting as shown in the below code sample.

Replacing Image

Following code sample shows how to replace the image of the found watermarks using GroupDocs.Watermark.

  • No labels