Jacob Collins Jacob is the JPedal Product Lead and specialises in PDF creation and manipulation. He also develops Salesforce backend systems and contributes to marketing and support. Outside of work, he’s a 1900‑rated chess player, guitarist, and French learner.

How to add a watermark to a PDF in Java (Tutorial)

2 min read

PDF thumbnail Java

TL;DR

Watermarking a PDF allows you to add branding, ownership information, or document status indicators onto your pages. While libraries like Apache PDFBox and iText can handle watermarking, they often require more manual handling and may struggle with complex PDFs or licensing limitations. JPedal provides a high-performance pure Java solution for reliably adding image, text, shape, and annotation based watermarks to PDFs with minimal code, making it especially suitable for enterprise workflows and batch processing.

What is a PDF watermark?

A watermark in a PDF file is a visual element placed behind or over the main content of the page. They are typically faint and translucent. The primary purpose of adding a watermark to a PDF is to convey document status (like “Confidential”) or company branding.

Why Add a Watermark to a PDF Using Java?

If you are building an automated document pipeline, you may want to watermark a PDF using Java to protect your intellectual property. You can programmatically stamp your name or logo so that you can be identified as the owner, or automatically mark unfinished documents with a “Draft” image before they are distributed.

Which Java PDF library should you choose?

When looking to add a watermark to a PDF in Java, there are several options to choose from, each with tradeoffs to consider:

  • Apache PDFBox and iText can both add watermarks to PDFs, but they often require low-level handling of content streams and rendering edge cases to work reliably across complex documents. PDFBox is a free Java API, but can struggle with performance and inconsistent rendering. iText provides a more powerful API, but introduces AGPL/commercial licensing constraints
  • JPedal is often preferred for enterprise Java PDF watermarking because its high-fidelity and high-performance engine handles complex PDFs with ease and consistency. It is the perfect tool for batch-processing large volumes of documents.

How to watermark a PDF in Java using JPedal

First, download the JPedal jar and then add it to your project.

To make edits to PDF files you can use JPedal’s PDFManipulator class. You can learn more about this powerful tool here. To get started we will create the basic structure for editing PDF files:


 

Now we can add different operations depending on what kind of watermarks we want to add.

Add a Watermark to All PDF Pages

You should rebuild the list of pages each time when loading a document, otherwise a document with more pages than the previous one will not have the watermark applied to the additional pages.


 

Add an Image Watermark to a PDF

To add an image watermark to a PDF:


Images may be transparent or in different colour spaces.
 

Add a Text Watermark to a PDF

To add a text watermark to a PDF:


You can also draw text at an angle.
 

Add a Shape Watermark

To draw a shape onto your PDF:


 

Using Annotations with Watermarks

Annotations by themselves are not suitable for watermarks as users can easily remove them. However, you could use an annotation to create a clickable hyperlink over your PDF watermarks.


 

Learn more

Looking for a pure Java PDF library to handle processing your documents? Check out JPedal.
Want to learn more about the PDF file format? We have been developing PDF software for over 20 years!



The JPedal PDF library allows you to solve these problems in Java


Jacob Collins Jacob is the JPedal Product Lead and specialises in PDF creation and manipulation. He also develops Salesforce backend systems and contributes to marketing and support. Outside of work, he’s a 1900‑rated chess player, guitarist, and French learner.