In Word documents the text can be broken so it continues on a new line, in a new column, or on a new page.

GemBox.Document represents these breaks with SpecialCharacter elements of a specific SpecialCharacterType type.

The following example shows how you can add various text breaks into a document.

Word document with SpecialCharacter elements
Screenshot of Word file with breaks
using GemBox.Document;

class Program
    static void Main()
        // If using Professional version, put your serial key below.

        var document = new DocumentModel();

        var section = new Section(document,
            new Paragraph(document,
                new Run(document, "First line."),
                new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                new Run(document, "Next line."),
                new SpecialCharacter(document, SpecialCharacterType.ColumnBreak),
                new Run(document, "Next column."),
                new SpecialCharacter(document, SpecialCharacterType.PageBreak),
                new Run(document, "Next page.")));

        section.PageSetup.TextColumns = new TextColumnCollection(2);


Imports GemBox.Document

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.

        Dim document As New DocumentModel()

        Dim section As New Section(document,
            New Paragraph(document,
                New Run(document, "First line."),
                New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                New Run(document, "Next line."),
                New SpecialCharacter(document, SpecialCharacterType.ColumnBreak),
                New Run(document, "Next column."),
                New SpecialCharacter(document, SpecialCharacterType.PageBreak),
                New Run(document, "Next page.")))

        section.PageSetup.TextColumns = New TextColumnCollection(2)



    End Sub
End Module

Most of the document operations that work with plain text, which accept String values, can handle the conversion of specific Char objects to SpecialCharacter elements. For instance, '\n' is converted to SpecialCharacterType.LineBreak, '\t' is converted to SpecialCharacterType.Tab, etc.

Among those operations are the Paragraph constructor, LoadText methods, and the MailMerge.Execute process.

However, note that Run constructor and Run.Text don't handle this conversion: the text that you provide to these operations shouldn't contain special characters like '\n', '\r', '\t', '\v' and '\f'.

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.

Like it?

Download Buy

If you want to try the GemBox.Document yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.