This article is useful for Java developers who are looking for a way to find and remove text or image watermarks from PDF, Word, Excel, PowerPoint, and Visio documents. In one of our posts we have learnt finding and removing watermarks from documents in C#. Let’s now jump to quickly see a little about a Java API that allows adding, finding and removing watermarks from various documents in different ways.
Java API for Watermarking and Removal
GroupDocs.Watermark for Java API supports adding text and image watermarks to a wide range of document formats. In addition, it also has the ability to find and remove watermarks from the documents. The API also finds the watermark objects that are added using the third-party tools. So let me demonstrate how you can remove the watermark from a document in a few steps in Java.
<repository> <id>GroupDocsJavaAPI</id> <name>GroupDocs Java API</name> <url>http://repository.groupdocs.com/repo/</url> </repository>
<dependency> <groupId>com.groupdocs</groupId> <artifactId>groupdocs-watermark</artifactId> <version>20.5</version> </dependency>
Steps to Remove Watermarks from a Document in Java
Before we begin, have a look at the following PDF document which contains a text watermark as well as an image watermark. We’ll use this document and remove the watermarks from it.
1. Create a new project.
2. Add the following imports.
3. Create an instance of Watermarker class and load the source document.
4. Find the watermarks based on the configured search criteria using search method.
5. Iterate over the watermarks collection and remove watermarks using removeAt method.
6. Save the resultant document using save method.
There are also some other ways of finding and removing watermarks from documents using different methods. If you want to remove all the watermarks of a document, or want to get rid of some selective watermarks of various kind:
- You can collect all the possible watermarks.
- Iterate over the watermark collection or directly access the watermark with index.
- Check for watermark type and data, if required.
- Remove it, if it meets your requirement.
remove, removeAt, and clear are the methods that can be used accordingly for removing watermarks. For more details, you can visit documentation article about searching and modifying watermarks in Java.
The following is the screenshot of the resultant PDF document that we get after removing the watermarks.
I believe, as a Java developer, you will not be hesitant any more to find and then remove any kind of watermarks from Microsoft and OpenOffice supported word-processing documents, spreadsheets, presentations, PDF documents, and Visio drawings.