Class PdfWatermark

java.lang.Object
cloud.opencode.base.pdf.content.PdfWatermark

public final class PdfWatermark extends Object
PDF Watermark - Watermark element for PDF documents PDF 水印 - PDF 文档的水印元素

Represents a text watermark that can be applied across all pages of a PDF document. This is a document-level decoration, not a page content element (not a PdfElement).

表示可应用于 PDF 文档所有页面的文本水印。 这是文档级别的装饰,不是页面内容元素(不是 PdfElement)。

Features | 主要功能:

  • Configurable text, rotation, opacity, color, font size - 可配置文本、旋转、透明度、颜色、字号
  • Fluent builder API for chained configuration - 流畅的链式配置 API
  • Default diagonal watermark appearance - 默认对角线水印外观

Usage Examples | 使用示例:

// Simple watermark
PdfWatermark watermark = PdfWatermark.text("CONFIDENTIAL");

// Customized watermark
PdfWatermark watermark = PdfWatermark.text("DRAFT")
    .rotation(-30f)
    .opacity(0.2f)
    .color(PdfColor.RED)
    .fontSize(80f);

Security | 安全性:

  • Thread-safe: No — mutable builder pattern - 线程安全: 否 — 可变构建器模式
  • Null-safe: text is required; color defaults to GRAY if null - 空值安全: text 必填;color 为 null 时默认为 GRAY
Since:
JDK 25, opencode-base-pdf V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • text

      public static PdfWatermark text(String text)
      Creates a text watermark 创建文本水印
      Parameters:
      text - watermark text | 水印文本
      Returns:
      PdfWatermark instance | PdfWatermark 实例
      Throws:
      NullPointerException - if text is null | 当 text 为 null 时
    • rotation

      public PdfWatermark rotation(float degrees)
      Sets rotation angle in degrees 设置旋转角度(度)
      Parameters:
      degrees - rotation angle | 旋转角度
      Returns:
      this watermark | 当前水印
    • opacity

      public PdfWatermark opacity(float opacity)
      Sets opacity level 设置透明度
      Parameters:
      opacity - opacity (0.0 transparent - 1.0 opaque) | 透明度(0.0 透明 - 1.0 不透明)
      Returns:
      this watermark | 当前水印
      Throws:
      IllegalArgumentException - if opacity is not in range [0.0, 1.0] | 当透明度不在 [0.0, 1.0] 范围时
    • color

      public PdfWatermark color(PdfColor color)
      Sets watermark color 设置水印颜色
      Parameters:
      color - watermark color | 水印颜色
      Returns:
      this watermark | 当前水印
      Throws:
      NullPointerException - if color is null | 当 color 为 null 时
    • fontSize

      public PdfWatermark fontSize(float size)
      Sets font size 设置字号
      Parameters:
      size - font size in points | 字号(磅)
      Returns:
      this watermark | 当前水印
      Throws:
      IllegalArgumentException - if size is not positive | 当字号不为正数时
    • font

      public PdfWatermark font(PdfFont font)
      Sets font (null for default Helvetica) 设置字体(null 表示默认 Helvetica)
      Parameters:
      font - font to use | 使用的字体
      Returns:
      this watermark | 当前水印
    • getText

      public String getText()
      Gets watermark text 获取水印文本
      Returns:
      watermark text | 水印文本
    • getRotation

      public float getRotation()
      Gets rotation angle in degrees 获取旋转角度
      Returns:
      rotation angle | 旋转角度
    • getOpacity

      public float getOpacity()
      Gets opacity 获取透明度
      Returns:
      opacity (0.0-1.0) | 透明度
    • getColor

      public PdfColor getColor()
      Gets watermark color 获取水印颜色
      Returns:
      watermark color | 水印颜色
    • getFontSize

      public float getFontSize()
      Gets font size 获取字号
      Returns:
      font size in points | 字号
    • getFont

      public PdfFont getFont()
      Gets font 获取字体
      Returns:
      font, or null for default Helvetica | 字体,null 表示默认 Helvetica
    • toString

      public String toString()
      Overrides:
      toString in class Object