Remove Watermarks from PDF Documents using Java

Remove Watermarks from PDF Documents using Java

The watermark image or text is used to identify the document’s author or copyright information. You can detect all the available watermarks in a document and then remove them. As a Java developer, you can easily remove watermarks from documents programmatically. In this article, you will learn how to remove watermarks from PDF documents using Java.

The following topics are discussed/covered in this article:

Java API for Watermark Removal

I will be using GroupDocs.Watermark for Java API for removing watermarks from PDF documents. It allows performing image and text watermarking operations. It also enables you to apply new watermarks, search and delete existing watermarks in files of supported formats such as Word, Excel, Powerpoint, and PDF.

You can download the JAR of the API or just add the following pom.xml configuration in your Maven-based Java applications to try the below-mentioned code examples.

<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>

Remove All Watermarks from PDF using Java

You can easily remove all watermarks from your PDF documents by following the simple steps mentioned below:

The following code sample shows how to remove all watermarks available in a PDF document using Java.

Remove All Watermarks from PDF using Java
Remove All Watermarks from PDF using Java

The Watermarker class facilitates adding, removing, and searching watermarks in a document.

The PossibleWatermarkCollection class represents a collection of possible watermarks found in a content.

The search() method of the Watermarker class searches all possible watermarks in the document. It returns the result set as PossibleWatermarkCollection.

Text Only Watermarks Removal from PDF using Java

You can easily remove all text-only watermarks from your PDF documents by following the simple steps mentioned below:

  • Create an instance of Watermarker class
  • Specify the path to the input PDF file
  • Populate PossibleWatermarkCollection by calling the search() method
  • Check if getText() is not null or empty for all PossibleWatermarks
  • Then pass the index to the removeAt() method to remove it
  • Save the updated file

The following code sample shows how to remove only the text watermarks available in a PDF document using Java.

Text Only Watermarks Removal from PDF using Java
Text Only Watermarks Removal from PDF using Java

The removeAt() method removes the item at the specified index from the PossibleWatermarksCollection.

Remove Watermarks with Particular Text Formatting

You can remove text watermarks available with particular formatting from your PDF documents by following the simple steps mentioned below:

The following code sample shows how to remove the text watermarks with particular text formatting from a PDF document using Java.

Remove Watermarks with Particular Text Formatting
Remove Watermarks with Particular Text Formatting

Image Only Watermarks Removal from PDF using Java

You can easily remove all image only watermarks from your PDF documents by following the simple steps mentioned below:

  • Create an instance of Watermarker class
  • Specify the path to the input PDF file
  • Populate PossibleWatermarkCollection by calling the search() method
  • Check if getImageData() is not null for all PossibleWatermarks
  • Then pass the index to the removeAt() method to remove it
  • Save the updated file

The following code sample shows how to remove only the image watermarks available in a PDF document using Java.

Image Only Watermarks Removal from PDF using Java
Image Only Watermarks Removal from PDF using Java

Get a Free License

You can try the API without evaluation limitations by requesting a free temporary license.

Conclusion

In this article, you have learned how to remove text or image watermarks from a PDF document using Java. Furthermore, you have learned how to remove text-only or image-only watermarks from documents. You can learn more about GroupDocs.Watermark for Java API using the documentation. In case of any ambiguity, please feel free to contact us on the forum.

See Also