Class PdfHeader

java.lang.Object
cloud.opencode.base.pdf.document.PdfHeader

public final class PdfHeader extends Object
PDF Header - Page header configuration for PDF documents PDF 页眉 - PDF 文档的页眉配置

Configures the header area that appears at the top of each page in a PDF document. Supports left, center, and right aligned text with page number placeholders.

配置 PDF 文档中每页顶部显示的页眉区域。 支持左、中、右对齐文本,以及页码占位符。

Features | 主要功能:

  • Three-column layout (left, center, right) - 三列布局(左、中、右)
  • Page number placeholders: {page} and {total} - 页码占位符: {page} 和 {total}
  • Optional separator line below header - 可选的页眉分隔线
  • Configurable font, size, and color - 可配置字体、字号和颜色

Usage Examples | 使用示例:

// Simple centered header
PdfHeader header = PdfHeader.of("My Document");

// Custom header with page numbers
PdfHeader header = PdfHeader.builder()
    .left("Report Title")
    .right("Page {page} of {total}")
    .fontSize(10f)
    .showLine(true);

Security | 安全性:

  • Thread-safe: No — mutable builder pattern - 线程安全: 否 — 可变构建器模式
  • Null-safe: text fields may be null (not rendered) - 空值安全: 文本字段可为 null(不渲染)
Since:
JDK 25, opencode-base-pdf V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • of

      public static PdfHeader of(String centerText)
      Creates a header with centered text 创建居中文本的页眉
      Parameters:
      centerText - center text | 居中文本
      Returns:
      PdfHeader instance | PdfHeader 实例
    • builder

      public static PdfHeader builder()
      Creates an empty header builder 创建空的页眉构建器
      Returns:
      PdfHeader builder | PdfHeader 构建器
    • left

      public PdfHeader left(String text)
      Sets left-aligned text 设置左对齐文本
      Parameters:
      text - left text (supports {page} and {total} placeholders) | 左侧文本(支持 {page} 和 {total} 占位符)
      Returns:
      this header | 当前页眉
    • center

      public PdfHeader center(String text)
      Sets center-aligned text 设置居中文本
      Parameters:
      text - center text (supports {page} and {total} placeholders) | 居中文本(支持 {page} 和 {total} 占位符)
      Returns:
      this header | 当前页眉
    • right

      public PdfHeader right(String text)
      Sets right-aligned text 设置右对齐文本
      Parameters:
      text - right text (supports {page} and {total} placeholders) | 右侧文本(支持 {page} 和 {total} 占位符)
      Returns:
      this header | 当前页眉
    • fontSize

      public PdfHeader fontSize(float size)
      Sets font size 设置字号
      Parameters:
      size - font size in points | 字号(磅)
      Returns:
      this header | 当前页眉
      Throws:
      IllegalArgumentException - if size is not positive | 当字号不为正数时
    • color

      public PdfHeader color(PdfColor color)
      Sets text color 设置文本颜色
      Parameters:
      color - text color | 文本颜色
      Returns:
      this header | 当前页眉
      Throws:
      NullPointerException - if color is null | 当 color 为 null 时
    • font

      public PdfHeader font(PdfFont font)
      Sets font 设置字体
      Parameters:
      font - font to use (null for default) | 使用的字体(null 表示默认)
      Returns:
      this header | 当前页眉
    • showLine

      public PdfHeader showLine(boolean show)
      Sets whether to show separator line below header 设置是否显示页眉下方分隔线
      Parameters:
      show - true to show line | true 表示显示分隔线
      Returns:
      this header | 当前页眉
    • getLeft

      public String getLeft()
      Gets left-aligned text 获取左对齐文本
      Returns:
      left text | 左侧文本
    • getCenter

      public String getCenter()
      Gets center-aligned text 获取居中文本
      Returns:
      center text | 居中文本
    • getRight

      public String getRight()
      Gets right-aligned text 获取右对齐文本
      Returns:
      right text | 右侧文本
    • getFontSize

      public float getFontSize()
      Gets font size 获取字号
      Returns:
      font size in points | 字号
    • getColor

      public PdfColor getColor()
      Gets text color 获取文本颜色
      Returns:
      text color | 文本颜色
    • getFont

      public PdfFont getFont()
      Gets font 获取字体
      Returns:
      font, or null for default | 字体,null 表示默认
    • isShowLine

      public boolean isShowLine()
      Checks if separator line is shown 检查是否显示分隔线
      Returns:
      true if line is shown | 如果显示分隔线返回 true
    • toString

      public String toString()
      Overrides:
      toString in class Object