Watermark Protected Docs using Java

Watermarks can be used to protect the content and claim ownership of your documents. Similarly, these can also be used for branding or labelling your documents as drafts. This article discusses how to add watermarks to the password-protected files in Java. We will add text, as well as image watermarks to the protected files using code examples.

The following topics are discussed here:

Java API to Watermark Password Protected Files

GroupDocs.Watermark showcases watermarking Java API that allows working with watermarks within your applications. We will use this API to insert text and image watermarks to the password-protected documents.

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

	<name>GroupDocs Java API</name>

Adding Watermark to Password-Protected Files using Java

Just a few lines of code allow you to customize the watermark as needed and apply it to your files. Follow the following steps for adding both types of watermark.

  • Load the protected file.
  • Apply watermark.
  • Save the watermarked file.

Now, we will add text watermarks, and then image watermarks, one by one.

Add Text Watermark to Protected Files in Java

Text watermarks can be used to mention the documents as DRAFT or CONFIDENTIAL; or for similar purposes. The following steps show how to add text watermark to password-protected documents in Java.

  • Prepare the loading option using the exsiting password.
  • Use the loading options to load the protected file with Watermarker class.
  • Define the watermark using TextWatermark class.
  • Set the text, appearance, rotation, opacity, color, and other properties of watermark.
  • Add the watermark to the document using the add() method.
  • Save the watermarked file using the save() method.

The following Java code snippet inserts a text watermark to a protected PDF document.

Add Image Watermark to Protected Files in Java

You can also insert any image or logo as a watermark. To add the image, use the ImageWatermark class. The following steps allow adding an image watermark to your password-protected documents in Java.

  • Prepare the loading option for the protected file using the exsiting password.
  • Load the file using the Watermarker class and loading option.
  • Load the image file using ImageWatermark class.
  • Set the watermark’s appearance, alignment, coordinates, rotation, opacity, and other properties.
  • Now, add watermark to document using add() method.
  • Finally, save the watermarked file using the save() method.

The following Java code example inserts an image watermark to the protected PDF file.

Get a Free API License

You can use the APIs for free by getting a temporary license.


To sum up, we discussed adding text watermarks, as well as image watermarks to password-protected files within the Java applications. Further, we customized the appearance of watermarks when these are applied to the documents.

In a similar vein, you can insert watermarks to the specific pages, slides, and sheets of documents, presentations, and workbooks respectively.

See the related articles for details and learn more from its documentation. For queries, contact us via the forum.

Related Articles