TX Text Control .NET: Removing Empty Pages
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…

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!
Related Posts
Create a Table of Contents in Windows Forms using C#
This article explains how to create a table of contents in Windows Forms using the ribbon or programmatically. Creating a table of contents is required to organize large documents.
Official TX Text Control .NET Sample Applications Are Now Hosted on GitHub
This article gives a quick overview of the new repositories, their structure and our plans for the future.
ASP.NETJavaScriptDocument Editor
Detect Toggle Button Changes Using a MutationObserver
This article shows how to detect changes of toggle buttons in the ribbon of the web editor using a MutationObserver. The state of a toggle button in the ribbon visualizes the state of a certain…
Two Ways to Restart Numbered Lists in TX Text Control
In TX Text Control, numbered lists are continued by default and need to be reset when required. There is more than one way if you want to restart numbered lists in a document. In this article, two…
Zoom Tricks: Disabling CTRL + MOUSE WHEEL and More
This article shows how to disable CTRL + MOUSE WHEEL, implement zooming with keyboard and reset the zoom factor to its default value.