PdfPage

A single PDF page. Obtained from PdfDocument.pages; not constructed directly.

val page = doc.pages[0]
println("${page.width} x ${page.height} pt, rotation ${page.rotation}°")
println(page.extractText())
for (link in page.annotations) { /* … */}

// Paint into any backend implementing KiteCanvas (see :kitepdf-compose-viewer etc.):
page.renderTo(canvas, deviceCtm = KiteMatrix.IDENTITY)

Properties

Link copied to clipboard

The indirect references of this page's annotations, in the order /Annots lists them. A caller that has an annotation's reference, such as a form field's widget, uses this to find which page holds it, without building every annotation.

Link copied to clipboard

Annotations attached to this page (links, highlights, etc.). Parsed from the page's /Annots array; empty when the page has none.

Link copied to clipboard

Extent of meaningful content (excluding margins, crop marks). Defaults to cropBox.

Link copied to clipboard

Region the page is to be clipped to for production-style output (printing with bleed). Defaults to cropBox when /BleedBox is absent. ISO 32000-1 §14.11.2.

Link copied to clipboard

The action the page's /AA /C entry names, run when the page closes (ISO 32000-1 §12.6.3, Table 195). Null when the page defines none.

Link copied to clipboard

Decoded content-stream bytes (FlateDecode etc. applied). May be empty. If /Contents is an array, the chunks are concatenated with a separating newline (per ISO 32000-1 §7.8.2: "The effect is as if all of the streams in the array were concatenated").

Link copied to clipboard
Link copied to clipboard

The region to display: cropBox clamped to mediaBox bounds (their intersection). Falls back to mediaBox when the intersection is empty or degenerate (zero/negative width or height).

Link copied to clipboard
open override val displayHeight: Double
Link copied to clipboard
open override val displayWidth: Double
Link copied to clipboard

mediaBox height, in points. See width for why this is not displayHeight.

Link copied to clipboard
val index: Int

Zero-based position in the document's flat page list.

Link copied to clipboard

Display label from /PageLabels (e.g. "iii", "A-1", "12"). Falls back to the one-based index as a string when the document doesn't define its own labels.

Link copied to clipboard

Page box in PDF user-space units (1/72 inch). left, bottom, right, top.

Link copied to clipboard

The action the page's /AA /O entry names, run when the page opens (ISO 32000-1 §12.6.3, Table 195). Null when the page defines none.

Link copied to clipboard

The page's own indirect reference (its entry in the parent's /Kids). null only for the unusual case of a page dict inlined directly in /Kids. The writer needs this to target the page object for edits.

Link copied to clipboard
Link copied to clipboard

Height of displayBox after applying rotationNormalized (dimensions swap at 90/270).

Link copied to clipboard

Width of displayBox after applying rotationNormalized (dimensions swap at 90/270).

Link copied to clipboard
Link copied to clipboard

rotation normalised into {0, 90, 180, 270}: reduced modulo 360 into [0, 360) then snapped to the nearest right angle (defensive: in practice the value is already a multiple of 90).

Link copied to clipboard

Structured text: spans clustered into lines, lines clustered into blocks. Use this when you need geometry (selection rectangles, search highlights) alongside the text. For a plain string, prefer extractText.

Link copied to clipboard

Intended dimensions of the finished page after trimming. Defaults to cropBox.

Link copied to clipboard

Multiplier for user-space units on this page (PDF 1.6+, §14.8.1). Default 1.0: each unit is 1/72 inch. A /UserUnit of 2.0 means each unit is 2/72 inch, doubling the effective page size for the same coordinate stream. Useful for very large pages (architectural drawings, posters).

Link copied to clipboard

mediaBox width, in points. This is the sheet, NOT what a viewer shows: it ignores /CropBox and /Rotate. For the on-screen size use displayWidth (or rotatedWidth, the same value).

Functions

Link copied to clipboard
open override fun displayToDeviceBase(): KiteMatrix
Link copied to clipboard

Extract page text using the naive Tj/TJ/' / " operator scan.

Link copied to clipboard

The form field whose widget covers the point, in page space, or null when none does.

Link copied to clipboard

The unscaled user-space -> device base transform, with the device origin at the top-left and y growing downward. The resulting device box is [0, rotatedWidth] x [0, rotatedHeight]. Compose additional scaling on top of this to fit a target surface.

Link copied to clipboard

rasterGeometry with the library's default allocation ceiling.

fun PdfPage.rasterGeometry(scale: Double = 1.0, maxPixels: Long): PdfRasterGeometry

The PdfRasterGeometry for rendering this page at scale device pixels per PDF user-space unit (so scale = dpi / 72.0). maxPixels prevents an untrusted page size, /UserUnit, or accidental scale from requesting an allocation large enough to terminate the host process.

Link copied to clipboard
fun renderAnnotationsTo(canvas: KiteCanvas, deviceCtm: KiteMatrix, formState: PdfFormState? = null, annotations: (PdfAnnotation) -> Boolean = { true })

Draws only the annotations annotations accepts, with none of the page's own content.

Link copied to clipboard
open override fun renderTo(canvas: KiteCanvas, deviceCtm: KiteMatrix)

Render this page into a KiteCanvas (typically the Compose binding's ComposeCanvas). deviceCtm is applied on top of user-space. Pass an identity matrix for a 1pt = 1pt rendering, or a scaled / Y-flipped matrix to fit a UI surface.

fun renderTo(canvas: KiteCanvas, deviceCtm: KiteMatrix, annotations: (PdfAnnotation) -> Boolean)

renderTo, drawing only the annotations annotations accepts. { false } renders the page content alone: for printing or exporting without markup, a clean thumbnail, or an editor that redraws its annotation layer on its own.

fun renderTo(canvas: KiteCanvas, deviceCtm: KiteMatrix, formState: PdfFormState?, annotations: (PdfAnnotation) -> Boolean = { true })

renderTo with the form being filled: a widget whose field has a value in formState is drawn from that value, and a field the state hides is not drawn. Pass null to render the file as it arrived.

Link copied to clipboard
fun PdfPage.search(needle: String, ignoreCase: Boolean = true): List<PdfSearchHit>

Find needle on this page. Matches may cross line boundaries inside a block (a break reads as one space, or joins directly after a hyphenated line with the hyphen dropped); they never cross block boundaries.

Link copied to clipboard
open override fun textContent(): KiteStructuredText