rtf-reader
Turns RTF bytes into events, plain text, or Markdown. This is the module most consumers start with.
Quick extract
import com.darkrockstudios.libs.rtfparserkmp.converter.extractPlainText
import com.darkrockstudios.libs.rtfparserkmp.converter.convertToMarkdown
val text: String = extractPlainText(rtfBytes)
val markdown: String = convertToMarkdown(rtfBytes)Drive the event stream
import com.darkrockstudios.libs.rtfparserkmp.parser.parseRtf
for (event in parseRtf(rtfBytes)) {
when (event) {
is RtfEvent.Text -> append(event.text)
else -> {}
}
}parseRtf has two forms: one returns a List<RtfEvent>, the other pushes to an RtfListener you supply. For full control over the input, instantiate StandardRtfParser and call parse with an RtfSource — a faithful, SAX-style port of RTFParserKit's Standard parser. Malformed input throws RtfParseException.
Pictures: each \pict group surfaces as one RtfEvent.Picture (RtfListener.processPicture) carrying the decoded image bytes, format, sizes and scale, placed between the pict command and the group's end, in whatever destination contains the group (for Word's body pictures that is shppict, not rtf). Its hex is never emitted as text, and the fallback copies Word writes inside \nonshppict and \shprslt are suppressed.