Class PdfText

java.lang.Object
cloud.opencode.base.pdf.content.PdfText
All Implemented Interfaces:
PdfElement

public final class PdfText extends Object implements PdfElement
PDF Text Element - Styled text content for PDF pages PDF 文本元素 - PDF 页面的带样式文本内容

Supports font, size, color, and various text styles.

支持字体、大小、颜色和各种文本样式。

Features | 主要功能:

  • Font, size, and color configuration - 字体、大小和颜色配置
  • Bold, italic, and underline styles - 粗体、斜体和下划线样式
  • Character and word spacing - 字符间距和单词间距
  • Text rotation - 文本旋转

Usage Examples | 使用示例:

PdfText title = PdfText.of("Hello, World!", 100, 700)
    .font(PdfFont.helveticaBold())
    .fontSize(24)
    .color(PdfColor.BLUE);

PdfText rotated = PdfText.of("Rotated", 200, 400)
    .rotation(45)
    .italic(true);

Security | 安全性:

  • Thread-safe: No — mutable builder pattern - 线程安全: 否 — 可变构建器模式
  • Null-safe: No — callers must ensure non-null values - 空值安全: 否 — 调用方需确保非空值
Since:
JDK 25, opencode-base-pdf V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • of

      public static PdfText of(String text, float x, float y)
      Creates text at position 在指定位置创建文本
      Parameters:
      text - text content | 文本内容
      x - x coordinate | x 坐标
      y - y coordinate | y 坐标
      Returns:
      PdfText instance | PdfText 实例
    • builder

      public static PdfText builder()
      Creates a text builder 创建文本构建器
      Returns:
      new PdfText instance for building | 用于构建的新 PdfText 实例
    • content

      public PdfText content(String text)
      Sets text content 设置文本内容
      Parameters:
      text - text content | 文本内容
      Returns:
      this text for chaining | 当前文本用于链式调用
    • position

      public PdfText position(float x, float y)
      Sets position 设置位置
      Parameters:
      x - x coordinate | x 坐标
      y - y coordinate | y 坐标
      Returns:
      this text for chaining | 当前文本用于链式调用
    • font

      public PdfText font(PdfFont font)
      Sets font 设置字体
      Parameters:
      font - font to use | 使用的字体
      Returns:
      this text for chaining | 当前文本用于链式调用
    • fontSize

      public PdfText fontSize(float size)
      Sets font size 设置字体大小
      Parameters:
      size - font size in points | 字体大小(点)
      Returns:
      this text for chaining | 当前文本用于链式调用
    • color

      public PdfText color(PdfColor color)
      Sets text color 设置文本颜色
      Parameters:
      color - text color | 文本颜色
      Returns:
      this text for chaining | 当前文本用于链式调用
    • color

      public PdfText color(int r, int g, int b)
      Sets text color from RGB values 从 RGB 值设置文本颜色
      Parameters:
      r - red component (0-255) | 红色分量
      g - green component (0-255) | 绿色分量
      b - blue component (0-255) | 蓝色分量
      Returns:
      this text for chaining | 当前文本用于链式调用
    • bold

      public PdfText bold(boolean bold)
      Sets bold style 设置粗体样式
      Parameters:
      bold - whether bold | 是否粗体
      Returns:
      this text for chaining | 当前文本用于链式调用
    • italic

      public PdfText italic(boolean italic)
      Sets italic style 设置斜体样式
      Parameters:
      italic - whether italic | 是否斜体
      Returns:
      this text for chaining | 当前文本用于链式调用
    • underline

      public PdfText underline(boolean underline)
      Sets underline style 设置下划线样式
      Parameters:
      underline - whether underlined | 是否下划线
      Returns:
      this text for chaining | 当前文本用于链式调用
    • characterSpacing

      public PdfText characterSpacing(float spacing)
      Sets character spacing 设置字符间距
      Parameters:
      spacing - character spacing | 字符间距
      Returns:
      this text for chaining | 当前文本用于链式调用
    • wordSpacing

      public PdfText wordSpacing(float spacing)
      Sets word spacing 设置单词间距
      Parameters:
      spacing - word spacing | 单词间距
      Returns:
      this text for chaining | 当前文本用于链式调用
    • rotation

      public PdfText rotation(float degrees)
      Sets rotation angle 设置旋转角度
      Parameters:
      degrees - rotation in degrees | 旋转角度
      Returns:
      this text for chaining | 当前文本用于链式调用
    • getContent

      public String getContent()
      Gets text content 获取文本内容
      Returns:
      text content | 文本内容
    • getX

      public float getX()
      Description copied from interface: PdfElement
      Gets the x coordinate of this element 获取元素的 x 坐标
      Specified by:
      getX in interface PdfElement
      Returns:
      x coordinate | x 坐标
    • getY

      public float getY()
      Description copied from interface: PdfElement
      Gets the y coordinate of this element 获取元素的 y 坐标
      Specified by:
      getY in interface PdfElement
      Returns:
      y coordinate | y 坐标
    • getFont

      public PdfFont getFont()
      Gets font 获取字体
      Returns:
      font | 字体
    • getFontSize

      public float getFontSize()
      Gets font size 获取字体大小
      Returns:
      font size | 字体大小
    • getColor

      public PdfColor getColor()
      Gets text color 获取文本颜色
      Returns:
      text color | 文本颜色
    • isBold

      public boolean isBold()
      Checks if bold 检查是否粗体
      Returns:
      true if bold | 如果粗体返回 true
    • isItalic

      public boolean isItalic()
      Checks if italic 检查是否斜体
      Returns:
      true if italic | 如果斜体返回 true
    • isUnderline

      public boolean isUnderline()
      Checks if underlined 检查是否下划线
      Returns:
      true if underlined | 如果下划线返回 true
    • getCharacterSpacing

      public float getCharacterSpacing()
      Gets character spacing 获取字符间距
      Returns:
      character spacing | 字符间距
    • getWordSpacing

      public float getWordSpacing()
      Gets word spacing 获取单词间距
      Returns:
      word spacing | 单词间距
    • getRotation

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