Mastering GroupDocs.Watermark in Java with groupdocs watermark maven

Protecting documents and images from unauthorized use is a top priority for developers and businesses alike. In this tutorial you’ll discover how to integrate groupdocs watermark maven into your Java projects, add text or image watermarks, embed logos, and even watermark multiple pages in a single operation. By the end, you’ll have a production‑ready solution for protect pdf with watermark, embed logo watermark pdf, and add image watermark java.

Quick Answers

  • What is the primary way to add GroupDocs.Watermark to a Maven project? Add the GroupDocs repository and groupdocs-watermark dependency to your pom.xml.
  • Can I watermark every page of a PDF at once? Yes – call watermarker.add(watermark) and the library applies it to all pages.
  • Is it possible to set a semi‑transparent logo as a watermark? Use ImageWatermark.setOpacity() to control transparency.
  • Do I need a license for development? A free trial works for evaluation; a commercial license is required for production.
  • Which Java version is required? Java 8 or higher is supported.

What is groupdocs watermark maven?

groupdocs watermark maven refers to the Maven‑based integration of the GroupDocs.Watermark library. By declaring the dependency in pom.xml, Maven automatically downloads the correct JARs, making it simple to start adding watermarks to PDFs, Word documents, images, and more.

Why use GroupDocs.Watermark for Java?

  • Robust format support – works with PDF, DOCX, PPTX, XLSX, PNG, JPEG, etc.
  • Fine‑grained control – opacity, rotation, scaling, and positioning are fully programmable.
  • Performance‑optimized – batch operations like watermarking multiple pages are handled efficiently.
  • Enterprise‑ready licensing – trial for testing, commercial license for production.

Prerequisites

  • Java SE 8+ installed.
  • Maven for dependency management.
  • An IDE such as IntelliJ IDEA or Eclipse.
  • Basic Java knowledge and familiarity with Maven’s pom.xml.

Setting Up GroupDocs.Watermark with Maven

1. Add the GroupDocs repository and dependency

Insert the following XML into your pom.xml. This step pulls the library from the official GroupDocs Maven repository.

<repositories>
   <repository>
      <id>repository.groupdocs.com</id>
      <name>GroupDocs Repository</name>
      <url>https://releases.groupdocs.com/watermark/java/</url>
   </repository>
</repositories>

<dependencies>
   <dependency>
      <groupId>com.groupdocs</groupId>
      <artifactId>groupdocs-watermark</artifactId>
      <version>24.11</version>
   </dependency>
</dependencies>

2. (Optional) Direct download

If you prefer not to use Maven, you can download the JAR manually from the official release page: GroupDocs.Watermark for Java releases.

3. Licensing

  1. Free trial – start with a trial key to explore features.
  2. Temporary license – useful for short‑term development or CI pipelines.
  3. Commercial license – required for production deployments.

Basic Initialization

Create a Watermarker instance pointing at the file you want to protect.

import com.groupdocs.watermark.Watermarker;

public class WatermarkSetup {
    public static void main(String[] args) {
        // Initialize watermarker with the path to your document
        Watermarker watermarker = new Watermarker("your-file-path");

        System.out.println("GroupDocs.Watermark initialized successfully!");
        
        // Remember to close the watermarker when done
        watermarker.close();
    }
}

Adding a Text Watermark (Protect PDF with Watermark)

Step‑by‑step

  1. Load the PDF using PdfLoadOptions.
  2. Create a TextWatermark with your desired text, font, and color.
  3. Adjust properties such as opacity and background color.
  4. Call watermarker.add(textWatermark) – this automatically applies the watermark to all pages (watermark multiple pages).
  5. Save the result.
import com.groupdocs.watermark.Watermarker;
import com.groupdocs.watermark.contents.WatermarkableImage;
import com.groupdocs.watermark.options.PdfLoadOptions;
import com.groupdocs.watermark.watermarks.TextWatermark;
import java.awt.Color;
import java.awt.Font;

public class AddTextWatermark {
    public static void main(String[] args) {
        // Load a PDF document
        PdfLoadOptions loadOptions = new PdfLoadOptions();
        Watermarker watermarker = new Watermarker("your-file-path.pdf", loadOptions);

        // Create and customize the text watermark
        TextWatermark textWatermark = new TextWatermark("Confidential", new Font("Arial", 36));
        textWatermark.setForegroundColor(Color.getRed());
        textWatermark.setBackgroundColor(Color.getWhite());
        textWatermark.setOpacity(0.5);
        
        // Add the watermark to all pages
        watermarker.add(textWatermark);

        // Save and close
        watermarker.save("output-file-path.pdf");
        watermarker.close();
    }
}

Key points

  • setOpacity(0.5) makes the watermark semi‑transparent, ideal for subtle protection.
  • The same approach works for watermark multiple pages without extra loops.

Adding an Image Watermark (Embed Logo Watermark PDF)

Step‑by‑step

  1. Load the target PDF.
  2. Create an ImageWatermark from a FileInputStream that points to your logo file (e.g., logo.png).
  3. Set the desired opacity to make the logo blend with the page content.
  4. Add the watermark to the document and save.
import com.groupdocs.watermark.Watermarker;
import com.groupdocs.watermark.contents.WatermarkableImage;
import com.groupdocs.watermark.options.PdfLoadOptions;
import com.groupdocs.watermark.watermarks.ImageWatermark;
import java.io.FileInputStream;
import java.io.IOException;

public class AddImageWatermark {
    public static void main(String[] args) throws IOException {
        // Load a PDF document
        PdfLoadOptions loadOptions = new PdfLoadOptions();
        Watermarker watermarker = new Watermarker("your-file-path.pdf", loadOptions);

        // Create and customize the image watermark
        ImageWatermark imageWatermark = new ImageWatermark(new FileInputStream("logo.png"));
        imageWatermark.setOpacity(0.5);
        
        // Add the watermark to all pages
        watermarker.add(imageWatermark);

        // Save and close
        watermarker.save("output-file-path.pdf");
        watermarker.close();
    }
}

Tips

  • Ensure the logo image has a transparent background for best results.
  • Adjust the opacity to balance visibility and readability of the underlying document.

Removing a Watermark (remove watermark java)

GroupDocs.Watermark focuses on adding watermarks, but you can clear all watermarks by loading the document, iterating through existing watermarks, and calling watermarker.remove(watermark) for each. This pattern lets you implement a “remove watermark” feature when needed.

Common Use Cases & Best Practices

ScenarioHow to Apply
Secure internal reportsUse a semi‑transparent text watermark on every page (protect pdf with watermark).
Branding marketing collateralEmbed a high‑resolution logo (embed logo watermark pdf) with 30‑40 % opacity.
Batch processing of imagesLoop through a folder, create an ImageWatermark for each image, and save the results (add image watermark java).
Legal documentsAdd a bold “CONFIDENTIAL” text watermark and lock the PDF after saving.
Multi‑page PDFsCall watermarker.add(watermark) once – the library automatically applies it to all pages (watermark multiple pages).

Pro tip: When working with large PDFs, enable streaming mode (PdfLoadOptions.setUseMemoryCache(true)) to reduce memory consumption.

FAQ’s

1. Can I add multiple watermarks to the same document using GroupDocs.Watermark?

Yes, you can add several watermarks—text and/or images—by calling the add() method multiple times before saving.

2. Is it possible to remove existing watermarks from a document with GroupDocs.Watermark?

GroupDocs.Watermark primarily focuses on adding watermarks. To remove or extract existing watermarks, you’ll need more advanced techniques or manual editing, depending on the document type.

3. Does GroupDocs.Watermark support watermarking for all file formats?

It supports many popular formats like PDF, Word, Excel, PowerPoint, images, and more, but always check their official documentation for specific format support.

4. Can I automate watermark placement and styling based on page layout or content?

Yes, you can programmatically control watermark positioning, size, and styling based on your logic, such as page dimensions or content areas.

5. Is there a way to apply transparent or semi-transparent watermarks in GroupDocs.Watermark?

Absolutely. Use the setOpacity() method to adjust transparency levels, enabling semi-transparent watermarks for subtle protection.

Additional Frequently Asked Questions

Q: How do I watermark only selected pages?
A: Load the document, retrieve the desired WatermarkablePage objects, and call watermarker.add(watermark, page) for each target page.

Q: Can I watermark password‑protected PDFs?
A: Yes – provide the password via PdfLoadOptions.setPassword("yourPassword") before loading.

Q: What is the recommended way to handle very large PDFs?
A: Enable memory caching (PdfLoadOptions.setUseMemoryCache(true)) and process pages in a streaming fashion to keep memory usage low.


Last Updated: 2026-02-03
Tested With: GroupDocs.Watermark 24.11
Author: GroupDocs