Class PdfText
java.lang.Object
cloud.opencode.base.pdf.content.PdfText
- All Implemented Interfaces:
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 Summary
Modifier and TypeMethodDescriptionbold(boolean bold) Sets bold style 设置粗体样式static PdfTextbuilder()Creates a text builder 创建文本构建器characterSpacing(float spacing) Sets character spacing 设置字符间距color(int r, int g, int b) Sets text color from RGB values 从 RGB 值设置文本颜色Sets text color 设置文本颜色Sets text content 设置文本内容Sets font 设置字体fontSize(float size) Sets font size 设置字体大小floatGets character spacing 获取字符间距getColor()Gets text color 获取文本颜色Gets text content 获取文本内容getFont()Gets font 获取字体floatGets font size 获取字体大小floatGets rotation 获取旋转角度floatGets word spacing 获取单词间距floatgetX()Gets the x coordinate of this element 获取元素的 x 坐标floatgetY()Gets the y coordinate of this element 获取元素的 y 坐标booleanisBold()Checks if bold 检查是否粗体booleanisItalic()Checks if italic 检查是否斜体booleanChecks if underlined 检查是否下划线italic(boolean italic) Sets italic style 设置斜体样式static PdfTextCreates text at position 在指定位置创建文本position(float x, float y) Sets position 设置位置rotation(float degrees) Sets rotation angle 设置旋转角度underline(boolean underline) Sets underline style 设置下划线样式wordSpacing(float spacing) Sets word spacing 设置单词间距
-
Method Details
-
of
-
builder
Creates a text builder 创建文本构建器- Returns:
- new PdfText instance for building | 用于构建的新 PdfText 实例
-
content
-
position
Sets position 设置位置- Parameters:
x- x coordinate | x 坐标y- y coordinate | y 坐标- Returns:
- this text for chaining | 当前文本用于链式调用
-
font
-
fontSize
Sets font size 设置字体大小- Parameters:
size- font size in points | 字体大小(点)- Returns:
- this text for chaining | 当前文本用于链式调用
-
color
-
color
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
Sets bold style 设置粗体样式- Parameters:
bold- whether bold | 是否粗体- Returns:
- this text for chaining | 当前文本用于链式调用
-
italic
Sets italic style 设置斜体样式- Parameters:
italic- whether italic | 是否斜体- Returns:
- this text for chaining | 当前文本用于链式调用
-
underline
Sets underline style 设置下划线样式- Parameters:
underline- whether underlined | 是否下划线- Returns:
- this text for chaining | 当前文本用于链式调用
-
characterSpacing
Sets character spacing 设置字符间距- Parameters:
spacing- character spacing | 字符间距- Returns:
- this text for chaining | 当前文本用于链式调用
-
wordSpacing
Sets word spacing 设置单词间距- Parameters:
spacing- word spacing | 单词间距- Returns:
- this text for chaining | 当前文本用于链式调用
-
rotation
Sets rotation angle 设置旋转角度- Parameters:
degrees- rotation in degrees | 旋转角度- Returns:
- this text 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 坐标
-
getFont
-
getFontSize
public float getFontSize()Gets font size 获取字体大小- Returns:
- font size | 字体大小
-
getColor
-
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 | 旋转角度
-