Text Continuation

When working with dynamic data, the length of text is not always known. Because of this, the TextArea and FormattedTextArea classes have built-in support for text continuation. This allows for quick and easy continuation of text over multiple columns or multiple pages.

This example shows how to flow text to multiple pages using a Text Area Page Element.

// Create a document.
Document document = new Document();
// Make a large text string.
string myText = "This is a test of the overflow text functionality.";
myText += myText;
myText += myText;
myText += myText;
myText += myText;
myText += myText;
// Adds pages until all text is displayed.
TextArea textArea = new TextArea( myText, 0, 0, 200, 200 );
do
{
    Page page = new Page();
    page.Elements.Add( textArea );
    document.Pages.Add( page );
    textArea = textArea.GetOverflowTextArea();
} while( textArea != null );
// Output the PDF.
document.Draw(pdfFilePath);        
' Create a document.
Dim MyDocument As Document = new Document()
' Make a large text string.
Dim MyText as String = "This is a test of the overflow text functionality."
MyText &= MyText
MyText &= MyText
MyText &= MyText
MyText &= MyText
MyText &= MyText
' Adds pages until all text is displayed.
Dim MyTextArea As TextArea = New TextArea( MyText, 0, 0, 200, 200 )
Do
    Dim MyPage As Page = New Page()
    MyPage.Elements.Add( MyTextArea )
    MyDocument.Pages.Add( MyPage )
    MyTextArea = MyTextArea.GetOverflowTextArea()
Loop While Not( MyTextArea Is Nothing )
' Output the PDF.
MyDocument.Draw(pdfFilePath)    

Both TextArea and FormattedTextArea have HasOverflowText methods. These methods can be used to test if there is text left over in the object that will not fit within the bounds of the area and therefore will not be output to the page. If this is true, the GetOverFlowTextArea (or GetOverFlowFormattedTextArea) method can be used to create a new TextArea (or FormattedTextArea) containing the overflow text. This object can then be placed in a different location on the same page or on the next page.

If there is no overflow text the GetOverflowTextArea (or GetOverFlowFormattedTextArea) method will return a null value. This makes it possible to place this object in a while loop until a null value is returned.

The RequiredHeight method can be used to get the height required to place all text in the TextArea (or FormattedTextArea) on the page.

In this topic