Add Watermark to PDF using Java

Add Watermark to PDF Java Logo

Watermarks are used to protect PDF documents or claim their ownership. Also, in various cases, watermarks are added to display the status of a PDF document such as draft, manuscript, etc. In order to automate watermarking, this article covers how to add a text or image watermark to the PDF using Java.

Java API to Add Watermark to PDF

In order to add a watermark to PDF documents, we will use Aspose.PDF for Java. It is a feature-rich API to create, process, and convert PDF files from within the Java applications. You can either download the API’s JAR or install it using the following Maven configurations.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-pdf</artifactId>
    <version>21.6</version>
</dependency>

Add Text Watermark to PDF in Java

The following are the steps to add a text watermark to PDF using Java.

The following code sample shows how to add a text watermark to a PDF document.

Output

The following is the screenshot of the watermarked PDF.

adding watermark to pdf in java

Add Image Watermark to PDF in Java

The following are the steps to add an image watermark to PDF using Java.

The following code sample shows how to add an image watermark to a PDF document.

Output

The following is the screenshot of the watermarked PDF.

Image watermark in PDF using Java

Get a Free API License

You can get a temporary license in order to use the API without evaluation limitations.

Conclusion

In this article, you have learned how to add a text or image watermark to a PDF using Java. Also, you have seen how to customize the appearance of the watermark using different properties. You can learn more about the Java PDF API using the documentation. In case you would have any questions, let us know via our forum.

See Also