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 the 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 the 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, '\v' 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'.

See also

Next steps

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. How about testing it today?

Download Buy