Package-level declarations

Types

Link copied to clipboard

T-30/T-81: text search over PDF pages, as a thin delegate to the shared core walker on io.github.yuroyami.kitepdf.core.KiteStructuredText (the same engine EPUB search uses). A hit is a KiteSearchHit: display-space quads (one per line touched) plus the matched text and page index.

Link copied to clipboard
data class PdfStructuredText(val pageWidth: Double, val pageHeight: Double, val blocks: List<PdfTextBlock>)

Structured text: pageGlyphs → spans → lines → blocks (ISO 32000-1 §14.8 is the spec basis; MuPDF's fz_stext_page is the architectural reference).

Link copied to clipboard
data class PdfTextBlock(val bounds: Rectangle, val lines: List<PdfTextLine>)

One paragraph-ish chunk: a vertical run of lines with no big gap. Block boundaries fall where vertical spacing exceeds GAP_TO_NEW_BLOCK × the median line height. It is a heuristic, not authoritative, but matches what readers consider "paragraph breaks" in the absence of structure tagging.

Link copied to clipboard
data class PdfTextLine(val bounds: Rectangle, val spans: List<PdfTextSpan>)

One line of text: spans whose Y origins cluster within Y_CLUSTER_TOL × font size. Spans are stored left-to-right.

Link copied to clipboard
data class PdfTextSpan(val text: String, val fontSpec: FontSpec, val fontSize: Double, val origin: Pair<Double, Double>, val bounds: Rectangle, val charEdgePoints: List<Pair<Double, Double>>? = null)

One renderer-drawText worth of glyphs that share font, size, and baseline. Position is the device-space origin (where the baseline starts).

Link copied to clipboard

Linear text extraction (ISO 32000-1 §9.4).

Functions

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

Find needle across the whole document, page by page. The result is a lazy Sequence, so a UI can surface incremental hits while later pages are still being extracted. See PdfPage.search for matching rules.

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.