Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,25 @@ jobs:

# Steps represent a sequence of watermark that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
submodules: true # Fetch Hugo themes
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
submodules: true
fetch-depth: 0
- name: Checkout theme repo
uses: actions/checkout@main
uses: actions/checkout@v4
with:
repository: groupdocs/tutorials-theme
token: ${{ secrets.REPO_TOKEN }}
fetch-depth: 0
path: themes/tutorials-theme
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install Theme Dependencies
run: npm install
working-directory: ./themes/tutorials-theme
# Step 2 - Sets up the latest version of Hugo
working-directory: ./themes/tutorials-theme
- name: Setup Hugo
uses: peaceiris/actions-hugo@v3
with:
Expand All @@ -54,7 +56,6 @@ jobs:
run: npm install -D --save postcss-cli
- name: Install Dependicies3
run: npm install -D postcss
# Also specifies the theme we want to use
- name: Build
run: hugo --configDir config/watermark --environment production --minify

Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: macos-latest
runs-on: ubuntu-latest

# Steps represent a sequence of watermark that will be executed as part of the job
steps:
Expand All @@ -39,12 +39,19 @@ jobs:
token: ${{ secrets.REPO_TOKEN }}
ref: beta
fetch-depth: 0
path: themes/tutorials-theme
path: themes/tutorials-theme
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install Theme Dependencies
run: npm install
working-directory: ./themes/tutorials-theme
# Step 2 - Sets up the latest version of Hugo
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: '0.97.3'
hugo-version: 'latest'
extended: true
- name: Install Dependicies1
run: npm install -D --save autoprefixer
Expand Down

Large diffs are not rendered by default.

225 changes: 225 additions & 0 deletions content/arabic/java/pdf-document-watermarking/_index.md

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
---
date: '2026-07-25'
description: 了解如何使用 GroupDocs.Watermark 库通过添加 Image Watermarks 为 Java 文档添加水印。面向开发者的逐步指南。
keywords:
- how to watermark java
- java add watermark pdf
- java add watermark word
- add image watermark java
lastmod: '2026-07-25'
og_description: 如何使用 GroupDocs.Watermark 为 Java 文档添加水印。本指南展示了添加 Image Watermarks、前置条件和最佳实践。
og_image_alt: 'Guide: Adding image watermarks to Java documents with GroupDocs.Watermark'
og_title: 如何为 Java 添加水印:使用 GroupDocs.Watermark 添加 Image Watermarks
schemas:
- author: GroupDocs
dateModified: '2026-07-25'
description: Learn how to watermark Java documents by adding image watermarks using
GroupDocs.Watermark library. Step‑by‑step guide for developers.
headline: 'How to Watermark Java: Add Image Watermarks with GroupDocs.Watermark'
type: TechArticle
- description: Learn how to watermark Java documents by adding image watermarks using
GroupDocs.Watermark library. Step‑by‑step guide for developers.
name: 'How to Watermark Java: Add Image Watermarks with GroupDocs.Watermark'
steps:
- name: Prepare the watermark image stream
text: '`FileInputStream` reads the watermark image from disk. This stream can
later be reused for multiple documents.'
- name: Initialize the Watermarker
text: The `Watermarker` class is the entry point for all watermark operations.
It loads the target document and exposes methods to add or remove watermarks.
- name: Create an ImageWatermark instance
text: '`ImageWatermark` represents the visual overlay. You can set opacity, size,
and position before applying it.'
- name: Apply the watermark
text: Call `add()` on the `Watermarker` instance, passing the configured `ImageWatermark`.
The library instantly renders the overlay onto each page.
- name: Save the watermarked file
text: Use `save()` to write the result to a new file. The method respects the
original format, preserving quality and metadata.
- name: Release resources
text: Always close your `FileInputStream` objects to avoid memory leaks, especially
when processing large batches.
- name: Create a FileInputStream for the Watermark Image
text: '`FileInputStream` loads the watermark image from the file system. Keep
the image size under 500 KB for optimal performance.'
- name: Initialize the Watermarker
text: The `Watermarker` class is GroupDocs.Watermark's core API object that represents
the document you are editing.
- name: Create an ImageWatermark Object
text: '`ImageWatermark` encapsulates the image and its visual properties (opacity,
rotation, scaling). Adjust these settings to match your branding guidelines.'
- name: Add the Watermark to the Document
text: Invoke `watermarker.add(imageWatermark)` to embed the watermark on every
page of the document.
type: HowTo
- questions:
- answer: '`Watermarker` is the primary API object that loads a document and provides
methods to add, edit, or remove watermarks.'
question: What is the Watermarker class?
- answer: Use `imageWatermark.setOpacity(0.5)` where the value ranges from 0 (transparent)
to 1 (fully opaque).
question: How do I set watermark opacity?
- answer: Yes – iterate over a directory, instantiate a new `Watermarker` for each
file, apply the same `ImageWatermark`, and save the result.
question: Can I batch‑process multiple files?
- answer: A temporary license is required for any non‑evaluation use; the free trial
works for up to 30 days.
question: Is a license mandatory for development builds?
- answer: Absolutely – pass the password to `Watermarker` via `LoadOptions.setPassword("yourPassword")`.
question: Does the library support password‑protected PDFs?
type: FAQPage
tags:
- watermark java
- GroupDocs.Watermark
- image watermark
- Java document protection
title: 如何为 Java 添加水印:使用 GroupDocs.Watermark 添加 Image Watermarks
type: docs
url: /zh/java/image-watermarks/add-image-watermarks-groupdocs-java/
weight: 1
---

# 如何在 Java 中添加图像水印:使用 GroupDocs.Watermark

在本教程中,您将了解 **how to watermark Java** 应用程序,方法是使用 GroupDocs.Watermark 库直接在文档中嵌入图像水印。无论是保护品牌资产还是执行版权,下面的步骤都将引导您完成干净、可投入生产的实现。

## 快速答复
- **需要哪个库?** GroupDocs.Watermark for Java ≥ 24.11.
- **支持哪个 Java 版本?** JDK 8 或更高。
- **我需要许可证吗?** 是 – 生产使用需要临时或完整许可证。
- **我可以给 PDF 和图像加水印吗?** 当然 – 该库支持 PDF、PNG、JPEG、DOCX、PPTX 等多种格式。
- **支持多少种格式?** 超过 50 种输入和输出格式,可在不将整个文件加载到内存的情况下处理数百页的文件。

## 什么是 “how to watermark java”?
*“How to watermark java”* 指的是在 Java 应用程序中以编程方式对文件(PDF、图像、Office 文档)应用可视水印的过程。此技术通过将可识别的标记直接嵌入内容,帮助保护知识产权和品牌形象。使用 GroupDocs.Watermark,您可以仅用几行代码在任何受支持的格式上实现自动化,从而在规模化时保持一致的保护。

## 为什么在 Java 中使用 GroupDocs.Watermark?
GroupDocs.Watermark 支持 **50+** 文档和图像格式,能够在内存使用低于 100 MB 的情况下处理大于 500 MB 的文件,并提供内置的缩放、不透明度和旋转选项。这些量化的能力使其成为企业级保护的可靠选择。

## 前置条件

- **GroupDocs.Watermark for Java** version 24.11 or later.
- **JDK 8+** (JDK 11 or newer is recommended for better performance).
- An IDE such as **IntelliJ IDEA** or **Eclipse**.
- Basic knowledge of Java I/O streams.

## 如何使用 GroupDocs.Watermark 为 Java 图像添加水印?

加载源图像,创建 `ImageWatermark` 对象,并仅通过几次方法调用将其应用于目标文档。`ImageWatermark` 表示可定位、缩放并设置不透明度的可视覆盖图像。库在内部处理流管理,因此您只需在保存后关闭流,即可实现批量处理的简便。

### 步骤 1:准备水印图像流
`FileInputStream` 从磁盘读取水印图像。此流随后可在多个文档中重复使用。

### 步骤 2:初始化 Watermarker
`Watermarker` 类是所有水印操作的入口点。它加载目标文档并提供添加或删除水印的方法。

### 步骤 3:创建 ImageWatermark 实例
`ImageWatermark` 表示可视覆盖层。您可以在应用之前设置不透明度、尺寸和位置。

### 步骤 4:应用水印
在 `Watermarker` 实例上调用 `add()`,并传入配置好的 `ImageWatermark`。库会立即在每页上渲染覆盖层。

### 步骤 5:保存加水印的文件
使用 `save()` 将结果写入新文件。该方法遵循原始格式,保留质量和元数据。

### 步骤 6:释放资源
始终关闭 `FileInputStream` 对象,以避免内存泄漏,尤其是在处理大批量时。

## 实现指南

### 使用流添加图像水印
本节详细解释每一步,并提供实际项目的实用技巧。

#### 步骤 1:为水印图像创建 FileInputStream
`FileInputStream` 从文件系统加载水印图像。为获得最佳性能,请将图像大小保持在 500 KB 以下。

#### 步骤 2:初始化 Watermarker
`Watermarker` 类是 GroupDocs.Watermark 的核心 API 对象,代表您正在编辑的文档。

#### 步骤 3:创建 ImageWatermark 对象
`ImageWatermark` 封装图像及其视觉属性(不透明度、旋转、缩放)。根据品牌指南调整这些设置。

#### 步骤 4:将水印添加到文档
调用 `watermarker.add(imageWatermark)` 将水印嵌入文档的每一页。

#### 步骤 5:保存加水印的文档
`watermarker.save("output_path")` 写入修改后的文件,同时保留原始格式。

#### 步骤 6:关闭所有资源
对每个 `FileInputStream` 调用 `close()` 可释放文件句柄并释放内存。

## 常见问题及解决方案

- **大 PDF 的内存激增** – 使用 `Watermarker.setLoadOptions(LoadOptions.memoryOptimized())` 懒惰地处理页面。
- **水印出现模糊** – 确保源图像至少为 300 dpi;库不会对低分辨率图像进行放大。
- **不受支持的格式错误** – 验证文件扩展名是否列在 [GroupDocs.Watermark supported formats](https://releases.groupdocs.com/watermark/java/) 中(覆盖超过 50 种格式)。

## 常见问题

**Q: Watermarker 类是什么?**
A: `Watermarker` 是主要的 API 对象,用于加载文档并提供添加、编辑或删除水印的方法。

**Q: 如何设置水印不透明度?**
A: 使用 `imageWatermark.setOpacity(0.5)`,其中值范围从 0(透明)到 1(完全不透明)。

**Q: 我可以批量处理多个文件吗?**
A: 可以 – 遍历目录,为每个文件实例化新的 `Watermarker`,应用相同的 `ImageWatermark`,并保存结果。

**Q: 开发构建是否必须使用许可证?**
A: 任何非评估使用都需要临时许可证;免费试用可使用至多 30 天。

**Q: 库是否支持受密码保护的 PDF?**
A: 当然 – 通过 `LoadOptions.setPassword("yourPassword")` 将密码传递给 `Watermarker`。

## 资源
- [文档](https://docs.groupdocs.com/watermark/java/)
- [API 参考](https://reference.groupdocs.com/watermark/java)
- [下载](https://releases.groupdocs.com/watermark/java/)
- [GroupDocs.Watermark for Java 发行版](https://releases.groupdocs.com/watermark/java/)
- [GitHub](https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-Java)
- [免费支持](https://forum.groupdocs.com/c/watermark/10)
- [临时许可证](https://purchase.groupdocs.com/temporary-license)

---

**最后更新:** 2026-07-25
**测试环境:** GroupDocs.Watermark 24.11 for Java
**作者:** GroupDocs

```xml
<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>
```

```java
import com.groupdocs.watermark.License;

public class WatermarkSetup {
public static void main(String[] args) {
// Apply license if available
License license = new License();
try {
license.setLicense("path/to/your/license.lic");
} catch (Exception e) {
System.out.println("Please apply for a free trial or purchase a license.");
}
}
}
```

```java
import java.io.FileInputStream;

// Load the watermark image from your directory
FileInputStream watermarkStream = new FileInputStream("YOUR_DOCUMENT_DIRECTORY/watermark.jpg");
```

```java
import com.groupdocs.watermark.Watermarker;

// Specify the document file path
Watermarker watermarker = new Watermarker("YOUR_DOCUMENT_DIRECTORY/input_image.png");
```

```java
import com.groupdocs.watermark.watermarks.ImageWatermark;

// Create a new ImageWatermark instance
ImageWatermark watermark = new ImageWatermark(watermarkStream);
```

```java
// Add watermark to the watermarked image
target.add(watermark);
```

```java
// Save the output document with the added watermark
target.save("YOUR_OUTPUT_DIRECTORY/output_image.png");
```

```java
// Properly release resources by closing streams and watermarker
watermark.close();
target.close();
watermarkStream.close();
```

## 相关教程

- [如何使用 GroupDocs.Watermark for Java 为 Word 文档添加图像水印](/watermark/java/word-processing-document-watermarking/add-image-watermarks-word-docs-groupdocs-watermark-java/)
- [如何使用 GroupDocs for Java 为 Excel 添加图像水印:完整指南](/watermark/java/image-watermarks/groupdocs-watermark-java-add-image-to-excel/)
- [使用 GroupDocs.Watermark for Java 为文档添加文字水印的指南](/watermark/java/text-watermarks/add-text-watermarks-groupdocs-java/)
Loading