Class PdfHeader
java.lang.Object
cloud.opencode.base.pdf.document.PdfHeader
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 Summary
Modifier and TypeMethodDescriptionstatic PdfHeaderbuilder()Creates an empty header builder 创建空的页眉构建器Sets center-aligned text 设置居中文本Sets text color 设置文本颜色Sets font 设置字体fontSize(float size) Sets font size 设置字号Gets center-aligned text 获取居中文本getColor()Gets text color 获取文本颜色getFont()Gets font 获取字体floatGets font size 获取字号getLeft()Gets left-aligned text 获取左对齐文本getRight()Gets right-aligned text 获取右对齐文本booleanChecks if separator line is shown 检查是否显示分隔线Sets left-aligned text 设置左对齐文本static PdfHeaderCreates a header with centered text 创建居中文本的页眉Sets right-aligned text 设置右对齐文本showLine(boolean show) Sets whether to show separator line below header 设置是否显示页眉下方分隔线toString()
-
Method Details
-
of
-
builder
Creates an empty header builder 创建空的页眉构建器- Returns:
- PdfHeader builder | PdfHeader 构建器
-
left
-
center
-
right
-
fontSize
Sets font size 设置字号- Parameters:
size- font size in points | 字号(磅)- Returns:
- this header | 当前页眉
- Throws:
IllegalArgumentException- if size is not positive | 当字号不为正数时
-
color
Sets text color 设置文本颜色- Parameters:
color- text color | 文本颜色- Returns:
- this header | 当前页眉
- Throws:
NullPointerException- if color is null | 当 color 为 null 时
-
font
-
showLine
Sets whether to show separator line below header 设置是否显示页眉下方分隔线- Parameters:
show- true to show line | true 表示显示分隔线- Returns:
- this header | 当前页眉
-
getLeft
-
getCenter
-
getRight
-
getFontSize
public float getFontSize()Gets font size 获取字号- Returns:
- font size in points | 字号
-
getColor
-
getFont
-
isShowLine
public boolean isShowLine()Checks if separator line is shown 检查是否显示分隔线- Returns:
- true if line is shown | 如果显示分隔线返回 true
-
toString
-