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.
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.
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.
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 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).
Searching Text Watermark Skipping Unreadable Characters
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.
GroupDocs.Watermark API enables you to easily find and remove a particular watermark from a document. Following code serves this purpose.
Replacing Text and Image in Found Watermarks
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.
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.
Following code sample shows how to replace the image of the found watermarks using GroupDocs.Watermark.