Class PdfParagraph
java.lang.Object
cloud.opencode.base.pdf.content.PdfParagraph
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionalignment(PdfParagraph.Alignment alignment) Sets text alignment 设置文本对齐static PdfParagraphbuilder()Creates a paragraph builder 创建段落构建器Sets text color 设置文本颜色Sets text content 设置文本内容firstLineIndent(float indent) Sets first line indent 设置首行缩进Sets font 设置字体fontSize(float size) Sets font size 设置字体大小getColor()floatgetFont()floatfloatfloatgetWidth()floatgetX()Gets the x coordinate of this element 获取元素的 x 坐标floatgetY()Gets the y coordinate of this element 获取元素的 y 坐标lineSpacing(float spacing) Sets line spacing multiplier 设置行间距倍数static PdfParagraphCreates paragraph at position with width 在指定位置创建指定宽度的段落position(float x, float y) Sets position 设置位置width(float width) Sets width 设置宽度
-
Method Details
-
of
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
Creates a paragraph builder 创建段落构建器- Returns:
- new PdfParagraph instance | 新 PdfParagraph 实例
-
content
Sets text content 设置文本内容- Parameters:
text- text content | 文本内容- Returns:
- this paragraph for chaining | 当前段落用于链式调用
-
position
Sets position 设置位置- Parameters:
x- x coordinate | x 坐标y- y coordinate | y 坐标- Returns:
- this paragraph for chaining | 当前段落用于链式调用
-
width
Sets width 设置宽度- Parameters:
width- max width | 最大宽度- Returns:
- this paragraph for chaining | 当前段落用于链式调用
-
font
Sets font 设置字体- Parameters:
font- font to use | 使用的字体- Returns:
- this paragraph for chaining | 当前段落用于链式调用
-
fontSize
Sets font size 设置字体大小- Parameters:
size- font size | 字体大小- Returns:
- this paragraph for chaining | 当前段落用于链式调用
-
color
Sets text color 设置文本颜色- Parameters:
color- text color | 文本颜色- Returns:
- this paragraph for chaining | 当前段落用于链式调用
-
lineSpacing
Sets line spacing multiplier 设置行间距倍数- Parameters:
spacing- line spacing (e.g., 1.5 for 150%) | 行间距倍数- Returns:
- this paragraph for chaining | 当前段落用于链式调用
-
alignment
Sets text alignment 设置文本对齐- Parameters:
alignment- text alignment | 文本对齐- Returns:
- this paragraph for chaining | 当前段落用于链式调用
-
firstLineIndent
Sets first line indent 设置首行缩进- Parameters:
indent- indent in points | 缩进(点)- Returns:
- this paragraph for chaining | 当前段落用于链式调用
-
getContent
-
getX
public float getX()Description copied from interface:PdfElementGets the x coordinate of this element 获取元素的 x 坐标- Specified by:
getXin interfacePdfElement- Returns:
- x coordinate | x 坐标
-
getY
public float getY()Description copied from interface:PdfElementGets the y coordinate of this element 获取元素的 y 坐标- Specified by:
getYin interfacePdfElement- Returns:
- y coordinate | y 坐标
-
getWidth
public float getWidth() -
getFont
-
getFontSize
public float getFontSize() -
getColor
-
getLineSpacing
public float getLineSpacing() -
getAlignment
-
getFirstLineIndent
public float getFirstLineIndent()
-