Cleaning up documents might be neccessary when building documents dynamically. Various document sections are added, forced page breaks are inserted at different positions and end-users can modify the resulting document. A typical task is to remove all empty pages from a document that consist only of a page break or section break character.

The following method uses the PageEnumerator to loop through all pages. If the Length of a page equals 1, the page is removed.

private void RemoveEmptyPages()
{
    TXTextControl.PageCollection.PageEnumerator pageEnum =
        textControl1.GetPages().GetEnumerator();

    pageEnum.MoveNext();

    int pageCounter = textControl1.GetPages().Count;

    for (int i = 0; i < pageCounter; i++)
    {
        TXTextControl.Page curPage =
            (TXTextControl.Page)pageEnum.Current;

        if (curPage.Length == 1)
        {
            textControl1.Select(curPage.Start - 1, 1);
            textControl1.Selection.Text = "";
        }
        else
            pageEnum.MoveNext();
    }
}

Need more of those tricks? Tell me what you need. As always: Happy Coding!