Watermark Word Files using Java

If you want to make sure your documents are safe and show they belong to you, you can use watermarks. This article will show you an easy way to add watermarks to your Word documents using Java. We’ll learn how to add text and image watermarks to Word documents using Java.

Here are some quick links to the topics we’ll cover:

Java Watermarking API

Today, we’ll use GroupDocs.Watermark for Java to help us with adding watermarks to Word documents. This library lets us add, remove, and change watermarks in files like Word documents, presentations, spreadsheets, images, and more. You can learn more about how to use it in its documentation.

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>

Adding Text Watermarks with Java

Watermarks for words are like special labels on your document. You can add them to one page or all pages. This is how you can do it:

  • Load your Word document using the Watermarker class.
  • Create a text watermark using the TextWatermark class.
  • Set how it looks by adding things like rotation angle, colors, and more.
  • Attach your text watermark to the Word document.
  • Save the document with the new watermark using the save method.

Here’s an example of how you can use Java to add a text watermark to a Word document:

When you use this code, you’ll see your chosen text on all pages of your Word document.

Example of Text Watermark in Word Document using Java

Adding Image Watermarks with Java

Just like text watermarks, you can also add images to your Word documents. Here’s how:

  • Load your Word document using the Watermarker class.
  • Get your logo or image ready using the ImageWatermark class.
  • Customize the watermark image by changing things like alignment and opacity.
  • Decide which page(s) you want your image on.
  • Attach your Image watermark to the Word document.
  • Save the document having the image watermark using the save method.

This is how the Java code looks when you want to add an image watermark to a Word document:

If you use this code, you’ll see your chosen image on the page you want in your Word document.

Example of Image Watermark in Word Document using Java

Getting a Free License

If you want to try this library without any limits, you can get a temporary free license.

Wrapping Up

To wrap things up, now you know how to add watermarks to Word documents using Java. We’ve learned how to add text as well as images as watermarks on different pages of Word files. If you want to learn more or have questions, you can check the documentation or ask for help on the forum.

See Also