Class PdfParagraph

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

public final class PdfParagraph extends Object implements PdfElement
PDF Paragraph - Multi-line text block with automatic word wrapping PDF 段落 - 自动换行的多行文本块

Supports line spacing, alignment, and text wrapping within a specified width.

支持行间距、对齐和在指定宽度内自动换行。

Features | 主要功能:

  • Automatic word wrapping within specified width - 在指定宽度内自动换行
  • Text alignment (left, center, right, justify) - 文本对齐(左、中、右、两端)
  • Line spacing and first-line indent - 行间距和首行缩进
  • Font and color customization - 字体和颜色自定义

Usage Examples | 使用示例:

PdfParagraph paragraph = PdfParagraph.of("Long text content...", 50, 700, 500)
    .fontSize(12)
    .lineSpacing(1.5f)
    .alignment(Alignment.JUSTIFY)
    .firstLineIndent(20);

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 PdfParagraph of(String text, float x, float y, float width)
      Creates paragraph at position with width 在指定位置创建指定宽度的段落
      Parameters:
      text - text content | 文本内容
      x - x coordinate | x 坐标
      y - y coordinate | y 坐标
      width - max width | 最大宽度
      Returns:
      PdfParagraph instance | PdfParagraph 实例
    • builder

      public static PdfParagraph builder()
      Creates a paragraph builder 创建段落构建器
      Returns:
      new PdfParagraph instance | 新 PdfParagraph 实例
    • content

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

      public PdfParagraph position(float x, float y)
      Sets position 设置位置
      Parameters:
      x - x coordinate | x 坐标
      y - y coordinate | y 坐标
      Returns:
      this paragraph for chaining | 当前段落用于链式调用
    • width

      public PdfParagraph width(float width)
      Sets width 设置宽度
      Parameters:
      width - max width | 最大宽度
      Returns:
      this paragraph for chaining | 当前段落用于链式调用
    • font

      public PdfParagraph font(PdfFont font)
      Sets font 设置字体
      Parameters:
      font - font to use | 使用的字体
      Returns:
      this paragraph for chaining | 当前段落用于链式调用
    • fontSize

      public PdfParagraph fontSize(float size)
      Sets font size 设置字体大小
      Parameters:
      size - font size | 字体大小
      Returns:
      this paragraph for chaining | 当前段落用于链式调用
    • color

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

      public PdfParagraph lineSpacing(float spacing)
      Sets line spacing multiplier 设置行间距倍数
      Parameters:
      spacing - line spacing (e.g., 1.5 for 150%) | 行间距倍数
      Returns:
      this paragraph for chaining | 当前段落用于链式调用
    • alignment

      public PdfParagraph alignment(PdfParagraph.Alignment alignment)
      Sets text alignment 设置文本对齐
      Parameters:
      alignment - text alignment | 文本对齐
      Returns:
      this paragraph for chaining | 当前段落用于链式调用
    • firstLineIndent

      public PdfParagraph firstLineIndent(float indent)
      Sets first line indent 设置首行缩进
      Parameters:
      indent - indent in points | 缩进(点)
      Returns:
      this paragraph for chaining | 当前段落用于链式调用
    • getContent

      public String getContent()
    • 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 坐标
    • getWidth

      public float getWidth()
    • getFont

      public PdfFont getFont()
    • getFontSize

      public float getFontSize()
    • getColor

      public PdfColor getColor()
    • getLineSpacing

      public float getLineSpacing()
    • getAlignment

      public PdfParagraph.Alignment getAlignment()
    • getFirstLineIndent

      public float getFirstLineIndent()