Interface PdfPage
public interface PdfPage
PDF Page - Represents a single page in a PDF document
PDF 页面 - 表示 PDF 文档中的单个页面
Provides methods to access page properties and add content elements such as text, images, tables, and graphics.
提供访问页面属性和添加内容元素(如文本、图像、表格和图形)的方法。
Features | 主要功能:
- Access page dimensions and orientation - 访问页面尺寸和方向
- Add text, paragraphs, and styled content - 添加文本、段落和带样式的内容
- Embed images - 嵌入图像
- Draw tables, lines, and rectangles - 绘制表格、线条和矩形
- Extract text content from page - 从页面提取文本内容
Usage Examples | 使用示例:
PdfPage page = document.addPage();
page.addText("Hello, World!", 100, 700)
.addText(PdfText.of("Styled", 100, 650).bold(true))
.addLine(PdfLine.of(50, 640, 550, 640))
.addRectangle(PdfRectangle.of(100, 500, 200, 100).fillColor(PdfColor.LIGHT_GRAY));
// Extract text
String text = page.extractText();
Security | 安全性:
- Thread-safe: No — implementations are not thread-safe; use one page per thread - 线程安全: 否 — 实现非线程安全,每个线程使用独立页面
- Since:
- JDK 25, opencode-base-pdf V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAdds an image to the page 向页面添加图像Adds a line to the page 向页面添加线条addParagraph(PdfParagraph paragraph) Adds a paragraph to the page 向页面添加段落addRectangle(PdfRectangle rectangle) Adds a rectangle to the page 向页面添加矩形Adds a table to the page 向页面添加表格Adds styled text element to the page 向页面添加带样式的文本元素Adds text to the page at specified position 在指定位置向页面添加文本Extracts all text from this page 从当前页面提取所有文本floatGets page height in points 获取页面高度(点)Gets page orientation 获取页面方向intGets page number (1-based) 获取页码(从1开始)Gets page size 获取页面大小intGets page rotation 获取页面旋转floatgetWidth()Gets page width in points 获取页面宽度(点)voidsetRotation(int degrees) Sets page rotation 设置页面旋转
-
Method Details
-
getPageNumber
int getPageNumber()Gets page number (1-based) 获取页码(从1开始)- Returns:
- page number | 页码
-
getPageSize
-
getWidth
float getWidth()Gets page width in points 获取页面宽度(点)- Returns:
- width | 宽度
-
getHeight
float getHeight()Gets page height in points 获取页面高度(点)- Returns:
- height | 高度
-
getOrientation
-
setRotation
void setRotation(int degrees) Sets page rotation 设置页面旋转- Parameters:
degrees- rotation degrees (0, 90, 180, 270) | 旋转角度- Throws:
IllegalArgumentException- if degrees is not 0, 90, 180, or 270 | 角度无效时抛出异常
-
getRotation
int getRotation()Gets page rotation 获取页面旋转- Returns:
- rotation degrees | 旋转角度
-
addText
-
addText
-
addParagraph
Adds a paragraph to the page 向页面添加段落- Parameters:
paragraph- paragraph element | 段落元素- Returns:
- this page for chaining | 当前页面用于链式调用
-
addImage
-
addTable
-
addLine
-
addRectangle
Adds a rectangle to the page 向页面添加矩形- Parameters:
rectangle- rectangle element | 矩形元素- Returns:
- this page for chaining | 当前页面用于链式调用
-
extractText
-