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 Details

    • getPageNumber

      int getPageNumber()
      Gets page number (1-based) 获取页码(从1开始)
      Returns:
      page number | 页码
    • getPageSize

      PageSize getPageSize()
      Gets page size 获取页面大小
      Returns:
      page size | 页面大小
    • getWidth

      float getWidth()
      Gets page width in points 获取页面宽度(点)
      Returns:
      width | 宽度
    • getHeight

      float getHeight()
      Gets page height in points 获取页面高度(点)
      Returns:
      height | 高度
    • getOrientation

      Orientation getOrientation()
      Gets page orientation 获取页面方向
      Returns:
      orientation | 方向
    • 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

      PdfPage addText(String text, float x, float y)
      Adds text to the page at specified position 在指定位置向页面添加文本
      Parameters:
      text - text content | 文本内容
      x - x coordinate | x 坐标
      y - y coordinate | y 坐标
      Returns:
      this page for chaining | 当前页面用于链式调用
    • addText

      PdfPage addText(PdfText pdfText)
      Adds styled text element to the page 向页面添加带样式的文本元素
      Parameters:
      pdfText - text element | 文本元素
      Returns:
      this page for chaining | 当前页面用于链式调用
    • addParagraph

      PdfPage addParagraph(PdfParagraph paragraph)
      Adds a paragraph to the page 向页面添加段落
      Parameters:
      paragraph - paragraph element | 段落元素
      Returns:
      this page for chaining | 当前页面用于链式调用
    • addImage

      PdfPage addImage(PdfImage image)
      Adds an image to the page 向页面添加图像
      Parameters:
      image - image element | 图像元素
      Returns:
      this page for chaining | 当前页面用于链式调用
    • addTable

      PdfPage addTable(PdfTable table)
      Adds a table to the page 向页面添加表格
      Parameters:
      table - table element | 表格元素
      Returns:
      this page for chaining | 当前页面用于链式调用
    • addLine

      PdfPage addLine(PdfLine line)
      Adds a line to the page 向页面添加线条
      Parameters:
      line - line element | 线条元素
      Returns:
      this page for chaining | 当前页面用于链式调用
    • addRectangle

      PdfPage addRectangle(PdfRectangle rectangle)
      Adds a rectangle to the page 向页面添加矩形
      Parameters:
      rectangle - rectangle element | 矩形元素
      Returns:
      this page for chaining | 当前页面用于链式调用
    • extractText

      String extractText()
      Extracts all text from this page 从当前页面提取所有文本
      Returns:
      extracted text | 提取的文本