TextExtractor

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

Walks content-stream operations for text-showing operators:

  • Tj : show a string

  • TJ : show an array of strings/spacing adjustments

  • ' : move to next line and show

  • " : set spacing, move to next line, and show

Show strings are decoded through the current font (set by Tf), so each font's /Encoding and /ToUnicode CMap apply. This is what makes composite Type 0 fonts (Identity-H, 2-byte codes) and embedded CJK extract correctly rather than byte-for-byte. When no font is resolvable the bytes fall back to PdfString.asText() (PDFDocEncoding / UTF-16BE BOM detection).

Line breaks are inserted on BT/ET, Td, TD, T*, Tm heuristics because PDF text positioning is geometric, not line-based.

Functions

Link copied to clipboard
fun extract(page: PdfPage): String

Font-blind overload for callers that have operations but no resources.