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 pages.
This example shows how to flow text to multiple pages using a Text Area Page Element:
[Java]
// Create a document.
Document document = new Document();
// Make a large text string.
StringBuffer myText = new StringBuffer("This is a test of the overflow text functionality.");
for (int i = 0; i < 5; i++) {
myText.append(myText);
}
// Adds pages until all text is displayed.
TextArea textArea = new TextArea(myText.toString(), 0, 0, 200, 200);
do {
Page page = new Page();
page.getElements().add(textArea);
document.getPages().add(page);
textArea = textArea.getOverflowTextArea();
} while (textArea != null);
// Output the PDF.
document.draw("[PhysicalPath]/MyDocument.pdf");
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.