Class PdfTable

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

public final class PdfTable extends Object implements 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:
  • Method Details

    • of

      public static PdfTable of(int columns)
      Creates a table with specified columns 创建指定列数的表格
      Parameters:
      columns - number of columns | 列数
      Returns:
      PdfTable instance | PdfTable 实例
    • builder

      public static PdfTable.Builder builder(int columns)
      Creates table builder 创建表格构建器
      Parameters:
      columns - number of columns | 列数
      Returns:
      Builder instance | Builder 实例
    • position

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

      public PdfTable width(float width)
      Sets table width 设置表格宽度
      Parameters:
      width - table width | 表格宽度
      Returns:
      this table for chaining | 当前表格用于链式调用
    • columnWidths

      public PdfTable columnWidths(float... widths)
      Sets column widths 设置列宽
      Parameters:
      widths - column widths | 列宽数组
      Returns:
      this table for chaining | 当前表格用于链式调用
    • header

      public PdfTable header(String... cells)
      Adds a header row 添加表头行
      Parameters:
      cells - header cells | 表头单元格
      Returns:
      this table for chaining | 当前表格用于链式调用
    • header

      public PdfTable header(PdfCell... cells)
      Adds a header row with PdfCell elements 添加包含 PdfCell 元素的表头行
      Parameters:
      cells - cell elements | 单元格元素
      Returns:
      this table for chaining | 当前表格用于链式调用
    • row

      public PdfTable row(String... cells)
      Adds a data row 添加数据行
      Parameters:
      cells - row cells | 行单元格
      Returns:
      this table for chaining | 当前表格用于链式调用
    • row

      public PdfTable row(PdfCell... cells)
      Adds a row with PdfCell elements 添加包含 PdfCell 元素的行
      Parameters:
      cells - cell elements | 单元格元素
      Returns:
      this table for chaining | 当前表格用于链式调用
    • borderWidth

      public PdfTable borderWidth(float width)
      Sets border width 设置边框宽度
      Parameters:
      width - border width | 边框宽度
      Returns:
      this table for chaining | 当前表格用于链式调用
    • borderColor

      public PdfTable borderColor(PdfColor color)
      Sets border color 设置边框颜色
      Parameters:
      color - border color | 边框颜色
      Returns:
      this table for chaining | 当前表格用于链式调用
    • headerBackground

      public PdfTable headerBackground(PdfColor color)
      Sets header background color 设置表头背景颜色
      Parameters:
      color - header background | 表头背景
      Returns:
      this table for chaining | 当前表格用于链式调用
    • alternateRowColors

      public PdfTable alternateRowColors(PdfColor oddColor, PdfColor evenColor)
      Sets alternating row colors 设置交替行颜色
      Parameters:
      oddColor - odd row color | 奇数行颜色
      evenColor - even row color | 偶数行颜色
      Returns:
      this table for chaining | 当前表格用于链式调用
    • cellPadding

      public PdfTable cellPadding(float padding)
      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: 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()
    • getColumnWidths

      public float[] getColumnWidths()
    • getHeaderRows

      public List<PdfCell[]> getHeaderRows()
    • getDataRows

      public List<PdfCell[]> getDataRows()
    • getBorderWidth

      public float getBorderWidth()
    • getBorderColor

      public PdfColor getBorderColor()
    • getHeaderBackground

      public PdfColor getHeaderBackground()
    • getOddRowColor

      public PdfColor getOddRowColor()
    • getEvenRowColor

      public PdfColor getEvenRowColor()
    • getCellPadding

      public float getCellPadding()