GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API.

Character Formatting

GemBox.Document supports a variety of text formatting options like font name, size and color; on / off properties like bold, italic, underline, strikethrough, subscript, superscript and many others.

Following example shows all available character formatting options.

Screenshot
Character Formatting Screenshot

See the full code below, use Run Example to execute.

using System;
using System.Globalization;
using GemBox.Document;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = new DocumentModel();

        document.Sections.Add(
            new Section(document,
                new Paragraph(document,
                    new Run(document, "All caps: "),
                    new Run(document, "Capital letters")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            AllCaps = true,
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Bold: "),
                    new Run(document, "Bold text")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            Bold = true
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Border: "),
                    new Run(document, "Some text")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            Border = new SingleBorder(BorderStyle.Single, Color.Black, 1)
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Double strikethrough: "),
                    new Run(document, "Some text")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            DoubleStrikethrough = true
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Font color: "),
                    new Run(document, "Blue text")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            FontColor = Color.Blue
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Font name: "),
                    new Run(document, "Arial Black")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            FontName = "Arial Black"
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Hidden: "),
                    new Run(document, "Hidden text")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            Hidden = true
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Text highlight color: "),
                    new Run(document, "Yellow background color")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            HighlightColor = Color.Yellow
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Italic: "),
                    new Run(document, "Italic text")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            Italic = true
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Kerning: "),
                    new Run(document, "Kerning is 15 points")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            Kerning = 15
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Position: "),
                    new Run(document, "Position is 3 points")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            Position = 3
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Scale: "),
                    new Run(document, "Scale is 125%")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            Scaling = 125
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Font size: "),
                    new Run(document, "Font size is 14 points")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            Size = 14
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Small caps: "),
                    new Run(document, "Some text")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            SmallCaps = true
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Spacing: "),
                    new Run(document, "Spacing is 1 point")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            Spacing = 1
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Strikethrough: "),
                    new Run(document, "Some text")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            Strikethrough = true
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Subscript: "),
                    new Run(document, "Some text")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            Subscript = true
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Superscript: "),
                    new Run(document, "Some text")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            Superscript = true
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Underline color: "),
                    new Run(document, "Underline color is blue")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            UnderlineColor = Color.Blue,
                            UnderlineStyle = UnderlineType.Single
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Underline style: "),
                    new Run(document, "Underline style is double")
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            UnderlineStyle = UnderlineType.Double
                        }
                    },
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Language: "),
                    new Field(document, FieldType.Date)
                    {
                        CharacterFormat = new CharacterFormat()
                        {
                            Language = CultureInfo.GetCultureInfo("de-DE")
                        }
                    })));

        document.Save("Character Formatting.docx");
    }
}
Imports System
Imports System.Globalization
Imports GemBox.Document

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document As DocumentModel = New DocumentModel

        document.Sections.Add(
            New Section(document,
                New Paragraph(document,
                    New Run(document, "All caps: "),
                    New Run(document, "Capital letters") With {
                        .CharacterFormat = New CharacterFormat() With {
                            .AllCaps = True
                        }
                    },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Bold: "),
                    New Run(document, "Bold text") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .Bold = True
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Border: "),
                    New Run(document, "Some text") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .Border = New SingleBorder(BorderStyle.Single, Color.Black, 1)
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Double strikethrough: "),
                    New Run(document, "Some text") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .DoubleStrikethrough = True
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Font color: "),
                    New Run(document, "Blue text") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .FontColor = Color.Blue
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Font name: "),
                    New Run(document, "Arial Black") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .FontName = "Arial Black"
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Hidden: "),
                    New Run(document, "Hidden text") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .Hidden = True
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Text highlight color: "),
                    New Run(document, "Yellow background color") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .HighlightColor = Color.Yellow
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Italic: "),
                    New Run(document, "Italic text") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .Italic = True
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Kerning: "),
                    New Run(document, "Kerning is 15 points") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .Kerning = 15
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Position: "),
                    New Run(document, "Position is 3 points") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .Position = 3
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Scale: "),
                    New Run(document, "Scale is 125%") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .Scaling = 125
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Font size: "),
                    New Run(document, "Font size is 14 points") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .Size = 14
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Small caps: "),
                    New Run(document, "Some text") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .SmallCaps = True
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Spacing: "),
                    New Run(document, "Spacing is 1 point") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .Spacing = 1
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Strikethrough: "),
                    New Run(document, "Some text") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .Strikethrough = True
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Subscript: "),
                    New Run(document, "Some text") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .Subscript = True
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Superscript: "),
                    New Run(document, "Some text") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .Superscript = True
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Underline color: "),
                    New Run(document, "Underline color is blue") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .UnderlineColor = Color.Blue,
                                .UnderlineStyle = UnderlineType.Single
                            }
                        },
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Underline style: "),
                    New Run(document, "Underline style is double") With {
                            .CharacterFormat = New CharacterFormat() With {
                                .UnderlineStyle = UnderlineType.Double
                            }
                        },
                     New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                     New Run(document, "Language: "),
                     New Field(document, FieldType.Date) With {
                            .CharacterFormat = New CharacterFormat() With {
                                .Language = CultureInfo.GetCultureInfo("de-DE")
                            }
                        })))

        document.Save("Character Formatting.docx")

    End Sub

End Module

Check next sample.