Class PdfTable
java.lang.Object
cloud.opencode.base.pdf.content.PdfTable
- All Implemented Interfaces:
PdfElement
PDF Table Element - Table with rows and cells
PDF 表格元素 - 包含行和单元格的表格
Supports headers, custom column widths, borders, and cell styling.
支持表头、自定义列宽、边框和单元格样式。
Features | 主要功能:
- Header and data rows - 表头行和数据行
- Custom column widths - 自定义列宽
- Alternating row colors - 交替行颜色
- Border and cell padding configuration - 边框和单元格内边距配置
- Fluent builder API - 流畅的构建器 API
Usage Examples | 使用示例:
PdfTable table = PdfTable.of(3)
.position(50, 600)
.width(500)
.header("Name", "Age", "City")
.row("Alice", "30", "New York")
.row("Bob", "25", "London")
.headerBackground(PdfColor.LIGHT_GRAY)
.cellPadding(8);
Security | 安全性:
- Thread-safe: No — mutable builder pattern - 线程安全: 否 — 可变构建器模式
- Null-safe: No — callers must ensure non-null values - 空值安全: 否 — 调用方需确保非空值
- Defensive copies: Column widths and row data are cloned - 防御性拷贝: 列宽和行数据已克隆
- 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 TypeMethodDescriptionalternateRowColors(PdfColor oddColor, PdfColor evenColor) Sets alternating row colors 设置交替行颜色borderColor(PdfColor color) Sets border color 设置边框颜色borderWidth(float width) Sets border width 设置边框宽度static PdfTable.Builderbuilder(int columns) Creates table builder 创建表格构建器cellPadding(float padding) Sets cell padding 设置单元格内边距columnWidths(float... widths) Sets column widths 设置列宽floatfloatintfloat[]floatgetWidth()floatgetX()Gets the x coordinate of this element 获取元素的 x 坐标floatgetY()Gets the y coordinate of this element 获取元素的 y 坐标Adds a header row with PdfCell elements 添加包含 PdfCell 元素的表头行Adds a header row 添加表头行headerBackground(PdfColor color) Sets header background color 设置表头背景颜色static PdfTableof(int columns) Creates a table with specified columns 创建指定列数的表格position(float x, float y) Sets position 设置位置Adds a row with PdfCell elements 添加包含 PdfCell 元素的行Adds a data row 添加数据行width(float width) Sets table width 设置表格宽度
-
Method Details
-
of
Creates a table with specified columns 创建指定列数的表格- Parameters:
columns- number of columns | 列数- Returns:
- PdfTable instance | PdfTable 实例
-
builder
Creates table builder 创建表格构建器- Parameters:
columns- number of columns | 列数- Returns:
- Builder instance | Builder 实例
-
position
Sets position 设置位置- Parameters:
x- x coordinate | x 坐标y- y coordinate | y 坐标- Returns:
- this table for chaining | 当前表格用于链式调用
-
width
Sets table width 设置表格宽度- Parameters:
width- table width | 表格宽度- Returns:
- this table for chaining | 当前表格用于链式调用
-
columnWidths
Sets column widths 设置列宽- Parameters:
widths- column widths | 列宽数组- Returns:
- this table for chaining | 当前表格用于链式调用
-
header
-
header
-
row
-
row
-
borderWidth
Sets border width 设置边框宽度- Parameters:
width- border width | 边框宽度- Returns:
- this table for chaining | 当前表格用于链式调用
-
borderColor
-
headerBackground
-
alternateRowColors
-
cellPadding
Sets cell padding 设置单元格内边距- Parameters:
padding- padding in points | 内边距(点)- Returns:
- this table for chaining | 当前表格用于链式调用
-
getColumns
public int getColumns() -
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() -
getColumnWidths
public float[] getColumnWidths() -
getHeaderRows
-
getDataRows
-
getBorderWidth
public float getBorderWidth() -
getBorderColor
-
getHeaderBackground
-
getOddRowColor
-
getEvenRowColor
-
getCellPadding
public float getCellPadding()
-