How to Apply Custom Watermarks to PDFs

IronPDF enables you to apply custom watermarks to PDF documents using HTML strings with full CSS support, allowing complete customization of text, images, opacity, rotation, and positioning for branding or security purposes.

Quickstart: Apply Watermarks to PDFs in Java

  1. Import IronPDF library and set your license key
  2. Load your PDF document using PdfDocument.fromFile()
  3. Create an HTML string for your watermark (text or image)
  4. Apply the watermark using pdf.applyWatermark(watermarkHtml)
  5. Save the watermarked PDF with pdf.saveAs()

```java :title=QuickStartWatermark.java PdfDocument pdf = PdfDocument.fromFile(Paths.get("sample.pdf")); pdf.applyWatermark(""); pdf.saveAs("watermarked.pdf");


Watermarking protects PDF documents and asserts ownership or status by marking them as "Confidential" or branding them with a logo. IronPDF provides a flexible solution using HTML strings with full CSS support. This enables complete customization through standard HTML and CSS properties.

This guide demonstrates different watermark types—text, image, location, opacity, and rotation adjustments—plus advanced methods using [TextStamper](https://ironpdf.com/java/object-reference/api/com/ironsoftware/ironpdf/stamp/TextStamper.html) and [ImageStamper](https://ironpdf.com/java/object-reference/api/com/ironsoftware/ironpdf/stamp/ImageStamper.html). For more PDF manipulation techniques, explore our guide on [creating PDFs](https://ironpdf.com/java/how-to/java-create-pdf-tutorial/) or learn about [adding backgrounds and foregrounds](https://ironpdf.com/java/how-to/background-foreground/).

<div class="hsg-featured-snippet">
    <h2>How to Apply Watermarks in Java</h2>
     <ol>
        <li><a class="js-modal-open" data-modal-id="download-modal" href="#download-modal">Download the Java library to apply watermarks to PDFs</a></li>
        <li>Render a new PDF or load an existing one</li>
        <li>Configure the HTML string or image to be used as a watermark</li>
        <li>Apply the watermark using the appropriate method</li>
        <li>Adjust parameters for opacity, rotation, and location as needed</li>
    </ol>
</div>

## How Do I Apply a Text Watermark to a PDF?

To apply a simple text watermark to a PDF document, use the `applyWatermark` method. This method accepts text using HTML and CSS for advanced styling. For example, add the text 'Confidential' in red to the PDF. This technique marks documents for internal use or indicates confidentiality status. The HTML approach provides flexibility through CSS properties including custom fonts, colors, sizes, and text effects.

```java
import java.io.IOException;
import java.nio.file.Paths;

import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;

public class Main {
    public static void main(String[] args) throws IOException {
        // Set the license key for IronPDF
        License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");

        // Load an existing PDF document from file
        PdfDocument pdf = PdfDocument.fromFile(Paths.get("sample.pdf"));

        // HTML string for watermark
        String watermarkHtml = "<h1 style='color:red;'>Confidential</h1>";

        // Apply the watermark using HTML string
        pdf.applyWatermark(watermarkHtml);

        // Save the PDF to a new file
        pdf.saveAs("text_watermark.pdf");
    }
}

The code demonstrates basic implementation. First, configure your IronPDF license to access all features. The watermark HTML accepts any valid HTML elements and CSS styling for complete control over appearance.

What Does the Text Watermark Look Like?

The resulting PDF file, 'text_watermark.pdf,' contains the specified watermark on all pages, with the text 'Confidential' displayed in red at the document center. By default, the watermark appears with 50% opacity to maintain readability while ensuring visibility.

For complex text formatting, explore our HTML to PDF conversion guide, which covers advanced HTML rendering techniques applicable to watermarks.


How Can I Add an Image as a Watermark?

Using the same method, apply images as watermarks, supporting formats including PNG, JPEG, SVG, and more. Style and position images using CSS within the HTML string. This feature adds company logos, certification seals, or branded elements to documents. Ensure images are accessible from the application's runtime environment.

import java.io.IOException;
import java.nio.file.Paths;

import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;

public class Main {
    public static void main(String[] args) throws IOException {
        // Set the license key for IronPDF
        License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");

        // Load an existing PDF document from file
        PdfDocument pdf = PdfDocument.fromFile(Paths.get("sample.pdf"));

        // Image HTML watermark
        String watermarkHtml = "<img src='logo.png' style='width:100px;'/>";

        // Apply the image watermark
        pdf.applyWatermark(watermarkHtml);

        // Save the PDF to a new file
        pdf.saveAs("image_watermark.pdf");
    }
}
import java.io.IOException;
import java.nio.file.Paths;

import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;

public class Main {
    public static void main(String[] args) throws IOException {
        // Set the license key for IronPDF
        License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");

        // Load an existing PDF document from file
        PdfDocument pdf = PdfDocument.fromFile(Paths.get("sample.pdf"));

        // Image HTML watermark
        String watermarkHtml = "<img src='logo.png' style='width:100px;'/>";

        // Apply the image watermark
        pdf.applyWatermark(watermarkHtml);

        // Save the PDF to a new file
        pdf.saveAs("image_watermark.pdf");
    }
}
JAVA

Use CSS properties for advanced styling with image watermarks:

// Example with more advanced CSS styling
String advancedWatermarkHtml = "<img src='logo.png' style='width:150px; opacity:0.5; transform:rotate(-45deg);'/>";
// Example with more advanced CSS styling
String advancedWatermarkHtml = "<img src='logo.png' style='width:150px; opacity:0.5; transform:rotate(-45deg);'/>";
JAVA

What File Formats Are Supported for Image Watermarks?

The resulting PDF file, 'image_watermark.pdf,' contains the image 'logo.png' as a watermark on all pages. The image displays at 100 pixels width. IronPDF supports formats including PNG, JPEG, GIF, SVG, and BMP. Use PNG images with transparent backgrounds for logo watermarks. To extract images from existing PDFs, see our guide on extracting images from PDFs.


How Do I Adjust Watermark Opacity and Position?

Customize watermark appearance by adjusting opacity and applying rotation. The applyWatermark method accepts both properties as parameters. Fine-tune these settings to ensure watermark visibility without obscuring document content. Opacity ranges from 0 (transparent) to 100 (opaque), with 20-40 providing optimal balance.

import java.io.IOException;
import java.nio.file.Paths;

import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.stamp.HorizontalAlignment;
import com.ironsoftware.ironpdf.stamp.VerticalAlignment;

public class Main {
    public static void main(String[] args) throws IOException {
        // Set the license key for IronPDF
        License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");

        // Load an existing PDF document from file
        PdfDocument pdf = PdfDocument.fromFile(Paths.get("sample.pdf"));

        // HTML string for watermark
        String watermarkHtml = "<h1 style='color:blue;'>Confidential</h1>";

        // Apply the HTML watermark with 30% opacity, positioned at the top-left corner of each page
        pdf.applyWatermark(watermarkHtml, 30, VerticalAlignment.TOP, HorizontalAlignment.LEFT);

        // Save the PDF to a new file
        pdf.saveAs("watermark_opacity_rotation.pdf");
    }
}
import java.io.IOException;
import java.nio.file.Paths;

import com.ironsoftware.ironpdf.License;
import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.stamp.HorizontalAlignment;
import com.ironsoftware.ironpdf.stamp.VerticalAlignment;

public class Main {
    public static void main(String[] args) throws IOException {
        // Set the license key for IronPDF
        License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01");

        // Load an existing PDF document from file
        PdfDocument pdf = PdfDocument.fromFile(Paths.get("sample.pdf"));

        // HTML string for watermark
        String watermarkHtml = "<h1 style='color:blue;'>Confidential</h1>";

        // Apply the HTML watermark with 30% opacity, positioned at the top-left corner of each page
        pdf.applyWatermark(watermarkHtml, 30, VerticalAlignment.TOP, HorizontalAlignment.LEFT);

        // Save the PDF to a new file
        pdf.saveAs("watermark_opacity_rotation.pdf");
    }
}
JAVA

For complex positioning, combine watermarks with other stamping features. Learn more in our backgrounds and foregrounds guide.

What Alignment Options Are Available?

The applyWatermark method applies HTML-based watermarks to all PDF pages with these options:

  • Opacity: Applied at 30% opacity for partial transparency
  • Vertical Alignment: Aligned to page TOP. Options include:
    • TOP: Watermark at page top
    • MIDDLE: Watermark at page middle
    • BOTTOM: Watermark at page bottom
  • Horizontal Alignment: Aligned to page LEFT. Options include:
    • LEFT: Watermark on left side
    • CENTER: Watermark at center
    • RIGHT: Watermark on right side

Combine alignment options to achieve nine positioning configurations, placing watermarks precisely without overlapping critical content. For documents requiring multiple watermarks or stamps in different positions, explore our annotations capabilities.

Frequently Asked Questions

How do I add a text watermark to a PDF in Java?

You can add a text watermark using IronPDF's applyWatermark method. Simply load your PDF document with PdfDocument.fromFile(), then call pdf.applyWatermark() with your text. The method accepts HTML strings, allowing you to style the watermark with CSS properties like color, font, and size.

Can I use images as watermarks instead of text?

Yes, IronPDF supports image watermarks. You can embed images in HTML strings passed to the applyWatermark method, or use the ImageStamper class for more advanced image watermarking with precise control over positioning and opacity.

How do I control the opacity of my watermark?

IronPDF allows you to control watermark opacity through CSS properties in your HTML string. You can set the opacity using the CSS opacity property (values from 0 to 1) or use RGBA color values for text transparency.

Can I rotate watermarks to appear diagonally across the page?

Yes, you can rotate watermarks using CSS transform properties in your HTML string. IronPDF's watermarking feature supports full CSS3 transforms, including rotation at any angle to create diagonal or angled watermarks.

What's the difference between using applyWatermark and TextStamper?

The applyWatermark method is simpler and uses HTML/CSS for styling, while TextStamper provides more programmatic control over text positioning, rotation, and opacity. TextStamper is ideal when you need precise placement or dynamic watermark generation.

How do I position watermarks at specific locations on the page?

IronPDF offers flexible positioning through CSS absolute positioning in HTML watermarks, or you can use TextStamper and ImageStamper classes which provide coordinate-based positioning for exact placement on PDF pages.

Can I add different watermarks to different pages?

Yes, IronPDF supports page-specific watermarking. You can use the stamper classes (TextStamper or ImageStamper) to apply watermarks to specific page ranges or individual pages within your PDF document.

Is it possible to add both text and image watermarks to the same PDF?

Absolutely. IronPDF allows multiple watermarks on the same document. You can combine text and image watermarks by either including both in a single HTML string or applying them separately using multiple watermarking operations.

Darrius Serrant
Full Stack Software Engineer (WebOps)

Darrius Serrant holds a Bachelor’s degree in Computer Science from the University of Miami and works as a Full Stack WebOps Marketing Engineer at Iron Software. Drawn to coding from a young age, he saw computing as both mysterious and accessible, making it the perfect medium for creativity ...

Read More
Ready to Get Started?
Version: 2026.1 just released