Text/List Continuation

The length of a text or list element is often unknown when working with dynamic data. Because the length is often unknown, the TextArea, FormattedTextArea, and HtmlArea classes have built-in text continuation support. This support allows a quick and easy continuation of text over multiple columns or pages.

The number of items in a list are also often unknown when working with dynamic data. The OrderedList and UnorderedList classes both have built-in list continuation support.

Not considering text/list overflow might cause your text to be truncated when a PDF is generated.

Text Over Flow

The TextArea, FormattedTextArea, and HtmlArea classes have methods for getting overflow text. In situations where there is overflow text, use the GetOverflowTextArea , GetOverflowFormattedTextArea, or GetOverflowHtmlArea method to create a new instance containing the overflow text. Then place the overflow text on the same page or a different page.

The GetOverflowTextArea method has three overloads. The GetOverflowFormattedTextArea has three overloads. And the GetOverflowHtmlArea has two overloads. Use one of the overloaded methods to place the new page element on a page.

Example

The following example illustrates handling overflow text when using a TextArea. The example sets the page element to the size of a typical page of text. It then loops through the page element, iteratively obtaining the amount of overflow and adding it to a new page until there is no more overflow.

Document document = new Document();
TextArea textArea = new(TextGenerator.GenerateLargeTextDoc(), 0, 0, 512, 692,
Font.Helvetica, 14);

do
{
    Page page = new Page();
    page.Elements.Add(textArea);
    document.Pages.Add(page);
    textArea = textArea.GetOverflowTextArea();
} while (textArea != null);
          
document.Draw(outputPath);
Dim document As New Document()

Dim textArea As New TextArea(TextGenerator.GenerateLargeTextDoc(), 0, 0, 512, 692, Font.Helvetica, 14)

Do
    Dim page As New Page()
    page.Elements.Add(textArea)
    document.Pages.Add(page)
    textArea = textArea.GetOverflowTextArea()
Loop While textArea IsNot Nothing

document.Draw(outputPath)

Text Overflow Figure 1. A document handling text overflow.

List Overflow

The OrderedList and UnorderedList classes both have support for determining if there is overflow. The OrderedList has the method: public OrderedList GetOverFlowList() while the UnorderedList has the method: public UnorderedList GetOverFlowList().

Example

The following example illustrates handling an OrderedList when the number of list items overflows the lists height.

Document document = new Document();
OrderedList ol = new OrderedList(0, 0, 512, 692);

for (int i = 0; i < 10; i++){
	ListItem item1 = ol.Items.Add("item " + i);
    OrderedSubList sl = item1.SubLists.AddOrderedSubList(NumberingStyle.AlphabeticLowerCase);
	for (int j = 0; j < 10; j++){
		ListItem subItem = sl.Items.Add("sub-item " + j);
    }
}

do
{
    Page page = new Page();
    page.Elements.Add(ol);
    document.Pages.Add(page);
    ol = ol.GetOverFlowList();
} while (ol != null);

document.Draw(outputPath);
Dim doc As New Document()

Dim ol As New OrderedList(0, 0, 512, 692)

ol.ListItemTopMargin = 5
ol.ListItemBottomMargin = 5

For i As Integer = 0 To 9
    Dim item1 As ListItem = ol.Items.Add("item " & i)

    Dim sl As OrderedSubList = item1.SubLists.AddOrderedSubList(NumberingStyle.AlphabeticLowerCase)

    For j As Integer = 0 To 9
        Dim subItem As ListItem = sl.Items.Add("sub-item " & j)
    Next
Next

Do
    Dim page As New Page()
    page.Elements.Add(ol)
    doc.Pages.Add(page)
    ol = ol.GetOverFlowList()
Loop While ol IsNot Nothing

doc.Draw(outputPath)

As the results illustrate, list overflow handles overflow due to sub-lists also.

List Overflow Figure 1. A document handling list overflow.

Obtaining Required Height

Correctly displaying a TextArea, FormattedTextArea, or HtmlArea often requires correctly setting the element's height. Use the GetRequiredHeight method (TextArea.GetRequiredHeight, FormattedTextArea.GetRequiredHeight,(HtmlArea.GetRequiredHeight ) to get the height necessary to place all text in the element correctly on a page.

Using GetRequiredHeight to obtain the value to set an element's height invalidates using that element's get overflow methods as the height now guarantees there is no overflow.

In this topic