Text Style
TextStyle is the character-level style object. It composes aFont, BackgroundColor, TextEffect,Border, Languages, and a CustomWidth hint.
Reusable Heading Style
Use case: Define a heading style once and reuse it in multiple paragraphs.
C#
1var heading = new TextStyle
2{
3 Font = new Font
4 {
5 Latin = new FontPart { FontName = "Calibri Light", Size = new FontSize(20), IsBold = true },
6 Color = Color.DarkBlue,
7 },
8};
9
10doc.AddParagraph().AddText(new Text("Chapter 1") { Style = heading });
Highlighted Warning Text
Use case: Draw attention to warnings using a background color.
C#
1var warning = new TextStyle
2{
3 Font = new Font
4 {
5 Latin = new FontPart { FontName = "Segoe UI", Size = new FontSize(12), IsBold = true },
6 Color = Color.DarkRed,
7 },
8BackgroundColor = Color.Yellow,
9};
10
11doc.AddParagraph().AddText(new Text("WARNING: Do not remove power.") { Style = warning });
Language-Aware Style
Use case: Correct shaping and hyphenation for CJK and RTL text.
C#
1using System.Globalization;
2
3var multilingual = new TextStyle
4{
5 Font = new Font
6 {
7 Latin = new FontPart { FontName = "Arial", Size = new FontSize(11) },
8 EastAsia = new FontPart { FontName = "Microsoft YaHei", Size = new FontSize(11) },
9 ComplexScriptFont = new FontPart { FontName = "Arial", Size = new FontSize(11) },
10 },
11Languages = new Languages
12{
13 Latin = new CultureInfo("en-US"),
14 EastAsia = new CultureInfo("zh-CN"),
15 ComplexScripts = new CultureInfo("ar-SA"),
16},
17};
Frequently asked questions
Can I inherit a TextStyle from another style?
Yes — set ReferenceStyleId (on BaseStyle) to the style you want to inherit from, then override individual properties.
Are TextStyle objects reusable across paragraphs?
Yes. Create them once and assign to as many Text runs as needed.