Class PageBuilder
java.lang.Object
cloud.opencode.base.pdf.document.PageBuilder
PDF Page Builder
PDF 页面构建器
Fluent API for adding content to a page.
用于向页面添加内容的流畅 API。
Features | 主要功能:
- Add text and paragraphs - 添加文本和段落
- Add images - 添加图像
- Add tables - 添加表格
- Draw graphics - 绘制图形
Usage Examples | 使用示例:
documentBuilder.addPage()
.text("Title", 100, 750)
.text("Content", 100, 700, PdfFont.helvetica(), 12)
.line(50, 720, 550, 720)
.image(Path.of("logo.png"), 50, 50, 100, 50)
.endPage();
Security | 安全性:
- Thread-safe: No — not designed for concurrent use - 线程安全: 否 — 非并发设计
- Null-safe: Yes — parameters are validated - 空值安全: 是 — 参数已验证
Performance | 性能特性:
- Time complexity: O(1) per element addition; O(e) overall where e is the number of elements added - 时间复杂度: 每次元素添加 O(1);整体为 O(e),e 为添加的元素数
- Space complexity: O(e) - element list grows proportionally to the number of content items added - 空间复杂度: O(e) - 元素列表与添加的内容项数成正比增长
- Since:
- JDK 25, opencode-base-pdf V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionellipse(PdfEllipse ellipse) Draws an ellipse.endPage()Finishes current page and returns to document builder.filledRectangle(float x, float y, float width, float height, PdfColor color) Draws a filled rectangle.floatGets page height in points.floatgetWidth()Gets page width in points.Adds a PdfImage element.Adds an image from file.Adds an image with size.line(float x1, float y1, float x2, float y2) Draws a line.Draws a line with style.nextPage()Adds another page.Adds another page with specific size.paragraph(PdfParagraph paragraph) Adds a paragraph.rectangle(float x, float y, float width, float height) Draws a rectangle.rectangle(PdfRectangle rectangle) Draws a rectangle element.Adds a table.tableBuilder(int columns) Creates table builder.Adds a PdfText element.Adds text at position.Adds styled text.
-
Method Details
-
text
Adds text at position. 在指定位置添加文本。- Parameters:
text- text content | 文本内容x- x coordinate | x 坐标y- y coordinate | y 坐标- Returns:
- this builder | 当前构建器
-
text
Adds styled text. 添加带样式的文本。- Parameters:
text- text content | 文本内容x- x coordinate | x 坐标y- y coordinate | y 坐标font- font to use | 使用的字体fontSize- font size | 字体大小- Returns:
- this builder | 当前构建器
-
text
Adds a PdfText element. 添加 PdfText 元素。- Parameters:
pdfText- text element | 文本元素- Returns:
- this builder | 当前构建器
-
paragraph
Adds a paragraph. 添加段落。- Parameters:
paragraph- paragraph element | 段落元素- Returns:
- this builder | 当前构建器
-
image
Adds an image from file. 从文件添加图像。- Parameters:
imagePath- image file path | 图像文件路径x- x coordinate | x 坐标y- y coordinate | y 坐标- Returns:
- this builder | 当前构建器
-
image
Adds an image with size. 添加指定大小的图像。- Parameters:
imagePath- image file path | 图像文件路径x- x coordinate | x 坐标y- y coordinate | y 坐标width- image width | 图像宽度height- image height | 图像高度- Returns:
- this builder | 当前构建器
-
image
Adds a PdfImage element. 添加 PdfImage 元素。- Parameters:
pdfImage- image element | 图像元素- Returns:
- this builder | 当前构建器
-
table
Adds a table. 添加表格。- Parameters:
table- table element | 表格元素- Returns:
- this builder | 当前构建器
-
tableBuilder
Creates table builder. 创建表格构建器。- Parameters:
columns- number of columns | 列数- Returns:
- table builder | 表格构建器
-
line
Draws a line. 绘制线条。- Parameters:
x1- start x | 起点 xy1- start y | 起点 yx2- end x | 终点 xy2- end y | 终点 y- Returns:
- this builder | 当前构建器
-
line
Draws a line with style. 绘制带样式的线条。- Parameters:
line- line element | 线条元素- Returns:
- this builder | 当前构建器
-
rectangle
Draws a rectangle. 绘制矩形。- Parameters:
x- x coordinate | x 坐标y- y coordinate | y 坐标width- rectangle width | 矩形宽度height- rectangle height | 矩形高度- Returns:
- this builder | 当前构建器
-
filledRectangle
Draws a filled rectangle. 绘制填充矩形。- Parameters:
x- x coordinate | x 坐标y- y coordinate | y 坐标width- rectangle width | 矩形宽度height- rectangle height | 矩形高度color- fill color | 填充颜色- Returns:
- this builder | 当前构建器
-
rectangle
Draws a rectangle element. 绘制矩形元素。- Parameters:
rectangle- rectangle element | 矩形元素- Returns:
- this builder | 当前构建器
-
ellipse
Draws an ellipse. 绘制椭圆。- Parameters:
ellipse- ellipse element | 椭圆元素- Returns:
- this builder | 当前构建器
-
endPage
Finishes current page and returns to document builder. 完成当前页面并返回文档构建器。- Returns:
- document builder | 文档构建器
-
nextPage
-
nextPage
Adds another page with specific size. 添加指定大小的另一个页面。- Parameters:
pageSize- page size | 页面大小- Returns:
- new page builder | 新页面构建器
-
getPageSize
-
getOrientation
-
getElements
-
getWidth
public float getWidth()Gets page width in points. 获取页面宽度(点)。- Returns:
- page width | 页面宽度
-
getHeight
public float getHeight()Gets page height in points. 获取页面高度(点)。- Returns:
- page height | 页面高度
-