Remove Watermarks from PDF Documents in Java

Watermarks are mostly used to mentioned documents as drafts and to avoid any illegal use of confidential documents. When draft as finalized or confidentiality is over, you can remove the watermarks from such documents. Watermarks can be either text or image-based. In this article, we will have a look about how to remove watermarks from PDF documents in Java.

Remove Watermark from PDF documents

Java API to Remove PDF Watermarks

GroupDocs.Watermark provides Java API to deal with watermarks within documents and images of different file formats. If you are making a watermark removal app, It provides you some useful ways to:

  • Remove all the watermarks from the PDF document
  • Remove hyperlink watermarks
  • Delete watermarks with particular text formatting

Let’s learn how a Java developer can remove watermarks from PDF using GroupDocs.Watermark for Java API in different ways. First of all, download and configure the API with your application.

Download or Configure

You can download the JAR file from the downloads section or use the latest repository and dependency Maven configurations within your Java applications.

<repository>
	<id>GroupDocsJavaAPI</id>
	<name>GroupDocs Java API</name>
	<url>https://repository.groupdocs.com/repo/</url>
</repository>
<dependency>
        <groupId>com.groupdocs</groupId>
        <artifactId>groupdocs-watermark</artifactId>
        <version>21.3</version> 
</dependency>

Remove All Watermarks from PDF Files in Java

The API gives you the power to easily find and then remove a particular watermark and all the watermarks from the document. The following steps show how to remove all the watermarks from a PDF document in Java.

  • Load the PDF document using Watermarker.
  • Fetch all the possible watermarks as a collection using search.
  • Traverse the whole collection and remove every watermark or the one that meets the criterion.
  • Save the updated PDF having no watermark on it.

The following Java code removes all the watermarks from a PDF document.

Remove Hyperlink Watermark in Java

The watermarking API allows to search and remove hyperlinks from the PDF document. The following steps allow removing hyperlink watermarks from a PDF document within the Java application.

  • Load the PDF file using Watermarker.
  • Fetch the possible watermarks as a collection using search.
  • Traverse the collection and remove the watermark(s) that meets the criterion.
  • Save the updated PDF with no more watermarks on it.

The following Java code sample shows how to find and remove hyperlink watermarks with a particular URL from a PDF document.

Remove Watermark from PDF with particular Text Formatting in Java

The watermark having the specific text formatting can also be removed. You can provide the font name, its size, color, etc as the search criterion. The API will find the watermarks having matched properties. The following steps demonstrate how to search and remove watermarks from a PDF file having a specific text formatting in Java.

  • Load the PDF file using Watermarker.
  • Set the search criterion using TextFormattingSearchCriteria.
  • Provide all the required formatting properties.
  • Search and get all the possible watermarks as a collection by providing the defined criteria.
  • Remove all the searched watermarks using the clear() method.
  • Save the updated PDF having no watermark with the defined properties.

The following Java code removes the watermarks in a PDF document having the specified text formatting.

Conclusion

To sum up, we learned ways to remove different watermarks from the PDF documents in Java. We specifically removed all the applied watermarks, then removed hyperlinks watermarks and watermarks with specific text formatting. Try building your own Java application for finding and removing the watermarks from PDF documents. Besides, you can learn more about GroupDocs.Watermark for Java from its documentation. For queries, contact us via the forum.

See Also