richText

fun richText(block: RichTextScope.() -> Unit)

Appends a multi-style paragraph. Lets a single paragraph mix bold, italic, coloured, or otherwise differently styled segments without splitting into separate text blocks.

Example:

richText {
span("This sentence has a ")
span("highlighted") { color = PdfColor.Red; bold = true }
span(" word and an ")
span("italic phrase") { italic = true }
span(" inside it.")
}

The block runs against a RichTextScope; every RichTextScope.span call adds one styled run, and the renderer wraps them all together.