Represents a class for watermark management in a document.
The following example demonstrates how to load and save a content of any supported format.
```
// Load a content from a file.
Watermarker watermarker = new Watermarker("D:\\input.pdf");
// Use methods of Watermarker class to add, search or remove watermarks.
// Save changes.
watermarker.save("D:\\output.pdf");
// Free resources.
watermarker.close();
```
Initializes a new instance of the [Watermarker](../../com.groupdocs.watermark/watermarker) class with the specified document path, load options and settings.
The following example demonstrates how to load and save a content of any supported format.
```
// Load a content from a file.
Watermarker watermarker = new Watermarker("D:\\input.pdf");
// Use methods of Watermarker class to add, search or remove watermarks.
// Save changes.
watermarker.save("D:\\output.pdf");
// Free resources.
watermarker.close();
```
Parameters:
Parameter
Type
Description
filePath
java.lang.String
The file path to load the document from.
Watermarker(String filePath, LoadOptions options)
public Watermarker(String filePath, LoadOptions options)
Initializes a new instance of the [Watermarker](../../com.groupdocs.watermark/watermarker) class with the specified document path and load options.
public Watermarker(String filePath, LoadOptions options, WatermarkerSettings settings)
Initializes a new instance of the [Watermarker](../../com.groupdocs.watermark/watermarker) class with the specified document path, load options and settings.
The following example demonstrates how to find particular text fragments in email message body/subject.
```
WatermarkerSettings settings = new WatermarkerSettings();
settings.setSearchableObjects(new SearchableObjects());
settings.getSearchableObjects().setEmailSearchableObjects(EmailSearchableObjects.Subject
| EmailSearchableObjects.HtmlBody
| EmailSearchableObjects.PlainTextBody);
EmailLoadOptions loadOptions = new EmailLoadOptions();
Watermarker watermarker = new Watermarker("D:\\test.msg", loadOptions, settings);
SearchCriteria criteria = new TextSearchCriteria("test", false);
// Note, search is performed only if you pass TextSearchCriteria instance to search() method
PossibleWatermarkCollection watermarks = watermarker.search(criteria);
// Remove found text fragments
watermarks.clear();
// Save changes
watermarker.save("D:\\modified_test.msg");
watermarker.close();
```
The following example demonstrates how to load and save a document of any supported format.
```
// Load a content from a stream.
FileInputStream inputStream = new FileInputStream("D:\\input.pdf");
FileOutputStream outputStream = new FileOutputStream("D:\\output.pdf");
Watermarker watermarker = new Watermarker(inputStream);
// Use methods of Watermarker class to add, search or remove watermarks.
// Save changes.
watermarker.save(outputStream);
watermarker.close();
outputStream.close();
inputStream.close();
```
The following example demonstrates how to set searchable objects globally (for all documents that
will be loaded after that).
```
WatermarkerSettings settings = new WatermarkerSettings();
settings.setSearchableObjects(new SearchableObjects());
settings.getSearchableObjects().setEmailSearchableObjects(EmailSearchableObjects.Subject
| EmailSearchableObjects.HtmlBody
| EmailSearchableObjects.PlainTextBody);
FileInputStream inputStream = new FileInputStream("D:\\test.msg");
FileOutputStream outputStream = new FileOutputStream("D:\\modified_test.msg");
EmailLoadOptions loadOptions = new EmailLoadOptions();
Watermarker watermarker = new Watermarker(inputStream, loadOptions, settings);
SearchCriteria criteria = new TextSearchCriteria("test", false);
// Note, search is performed only if you pass TextSearchCriteria instance to search() method
PossibleWatermarkCollection watermarks = watermarker.search(criteria);
// Remove found text fragments
watermarks.clear();
// Save changes
watermarker.save(outputStream);
watermarker.close();
outputStream.close();
inputStream.close();
```
public final SearchableObjects getSearchableObjects()
Gets the content objects that are to be included in a watermark search.
This mathod also specifies content objects which are used in image search.
For more information see #search(SearchCriteria).search(SearchCriteria)
and #getImages().getImages() methods.
The following example demonstrates how to remove all XObjects and Artifacts from a pdf document.
```
Watermarker watermarker = new Watermarker("D:\\test.pdf");
watermarker.getSearchableObjects().setPdfSearchableObjects(PdfSearchableObjects.XObjects
| PdfSearchableObjects.Artifacts);
PossibleWatermarkCollection watermarks = watermarker.search();
// Remove all found objects.
watermarks.clear();
// Save changes.
watermarker.save("D:\\modified_test.pdf");
watermarker.close();
```
Returns:SearchableObjects - The objects that are to be included in a watermark search.
setSearchableObjects(SearchableObjects value)
public final void setSearchableObjects(SearchableObjects value)
Sets the content objects that are to be included in a watermark search.
This mathod also specifies content objects which are used in image search.
For more information see #search(SearchCriteria).search(SearchCriteria)
and #getImages().getImages() methods.
Learn more about searching watermarks:
Searching watermarks.
The following example demonstrates how to remove all XObjects and Artifacts from a pdf document.
```
Watermarker watermarker = new Watermarker("D:\\test.pdf");
watermarker.getSearchableObjects().setPdfSearchableObjects(PdfSearchableObjects.XObjects
| PdfSearchableObjects.Artifacts);
PossibleWatermarkCollection watermarks = watermarker.search();
// Remove all found objects.
watermarks.clear();
// Save changes.
watermarker.save("D:\\modified_test.pdf");
watermarker.close();
```
The following example demonstrates how to find and remove the first possible watermark containing particular
text or image from a document of any supported type.
```
Watermarker watermarker = new Watermarker("D:\\input.doc");
ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria("D:\\logo.png");
TextSearchCriteria textSearchCriteria = new TextSearchCriteria(Pattern.compile("^Company\\sName$"));
PossibleWatermarkCollection watermarks = watermarker.search(textSearchCriteria.or(imageSearchCriteria));
if (watermarks.getCount() > 0)
{
watermarker.remove(watermarks.get_Item(0));
}
watermarker.save("D:\\output.doc");
watermarker.close();
```
The following example demonstrates how to find and remove all possible watermarks containing particular
text or image from a document of any supported type.
```
Watermarker watermarker = new Watermarker("D:\\input.doc");
ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria("D:\\logo.png");
TextSearchCriteria textSearchCriteria = new TextSearchCriteria(Pattern.compile("^Company\\sName$"));
PossibleWatermarkCollection watermarks = watermarker.search(textSearchCriteria.or(imageSearchCriteria));
watermarker.remove(watermarks);
watermarker.save("D:\\output.doc");
watermarker.close();
```
The following example demonstrates how to add the watermark and save the document to another file
with default [SaveOptions](../../com.groupdocs.watermark.options/saveoptions).
```
Watermarker watermarker = new Watermarker("input.pdf");
TextWatermark watermark = new TextWatermark("top secret", new Font("Arial", 36));
watermarker.add(watermark);
watermarker.save("output.pdf", new SaveOptions());
watermarker.close();
```
The following example demonstrates how to add watermark and save the document to the memory stream
with default [SaveOptions](../../com.groupdocs.watermark.options/saveoptions).
```
Watermarker watermarker = new Watermarker("input.pdf");
TextWatermark watermark = new TextWatermark("top secret", new Font("Arial", 36));
watermarker.add(watermark);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
watermarker.save(outputStream, new SaveOptions());
// ...
outputStream.close();
watermarker.close();
```
The following example demonstrates how to find and remove all possible watermarks containing particular text
or image from a document of any supported type.
```
Watermarker watermarker = new Watermarker("input.doc");
ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria("logo.png");
TextSearchCriteria textSearchCriteria = new TextSearchCriteria(Pattern.compile("^Company\\sName$"));
PossibleWatermarkCollection watermarks = watermarker.search(textSearchCriteria.or(imageSearchCriteria));
watermarks.clear();
watermarker.save("output.doc");
watermarker.close();
```
The following example demonstrates how to add watermark to all images in a document of any supported type.
```
Watermarker watermarker = new Watermarker("input.doc");
// Initialize text or image watermark.
TextWatermark watermark = new TextWatermark("DRAFT", new Font("Arial", 19));
// Find all images in the document.
WatermarkableImageCollection images = watermarker.getImages();
// Add watermark.
for (WatermarkableImage watermarkableImage : images)
{
watermarkableImage.addWatermark(watermark);
}
// Save changes.
watermarker.save("output.doc");
watermarker.close();
```