Simply pass the string of text you need to insert into the document to the Write method. Text formatting is determined by the Font property. This object contains different font attributes (font name, font size, color, and so on).
Some important font attributes are also represented by DocumentBuilder properties to allow you to access them directly. These are boolean properties Bold, Italic, and Underline.
Note that the character formatting you set will apply to all text inserted from the current position in the document onwards.
Example DocumentBuilderInsertText
Inserts formatted text using DocumentBuilder.
[C#]
DocumentBuilder builder = new DocumentBuilder();
// Specify font formatting before adding text.
Aspose.Words.Font font = builder.Font;
font.Size = 16;
font.Bold = true;
font.Color = Color.Blue;
font.Name = "Arial";
font.Underline = Underline.Dash;
builder.Write("Sample text.");
[Visual Basic]
Dim builder As DocumentBuilder = New DocumentBuilder()
' Specify font formatting before adding text.
Dim font As Aspose.Words.Font = builder.Font
font.Size = 16
font.Bold = True
font.Color = Color.Blue
font.Name = "Arial"
font.Underline = Underline.Dash
builder.Write("Sample text.")
[Java]
DocumentBuilder builder = new DocumentBuilder();
// Specify font formatting before adding text.
Font font = builder.getFont();
font.setSize(16);
font.setBold(true);
font.setColor(Color.BLUE);
font.setName("Arial");
font.setUnderline(Underline.DASH);
builder.write("Sample text.");