Text Continuation
A text's length is often unknown when working with dynamic data. Because the length is often unknown, the TextArea and FormattedTextArea classes have built-in text continuation support. This support allows a quick and easy continuation of text over multiple columns or pages.
Not considering text overflow might cause your text to be truncated when a PDF is generated.
Text Over Flow
Both the TextArea and FormattedTextArea classes have methods for getting overflow text and for getting overflow text and the overflow text's area. These classes also have a method for testing if the text has text overflow. The TextArea and FormattedTextArea have HasOverflowText methods (TextArea.HasOverflowText, FormattedTextArea.HasOverflowText).
public bool HasOverflowText()
These methods test if there is remaining text not fitting within the bounds of the area and, therefore, not outputted to the page.
In situations where there is overflow text, use the GetOverflowTextArea (or GetOverflowFormattedTextArea) methods to create a new TextArea (or FormattedTextArea) containing the overflow text. Overflow text can then be placed in a different location on the same page or the next page.
The GetOverflowTextArea has three overloads.
public TextArea GetOverflowTextArea()
public TextArea GetOverflowTextArea(float x, float y)
public TextArea GetOverflowTextArea(float x, float y, float width, float height)
Refer to the API documentation of any of the three overloaded methods for complete examples of the (GetOverflowTextArea(), GetOverflowTextArea(float x, float y), and GetOverflowTextArea(float x, float y, float width, float height) methods).
The GetOverflowFormattedTextArea has three overloads.
public FormattedTextArea GetOverflowFormattedTextArea()
public FormattedTextArea GetOverflowFormattedTextArea(float x, float y)
public FormattedTextArea GetOverflowFormattedTextArea(float x, float y, float height)
Refer to the API documentation of any of the three overloaded methods for complete examples of each (GetOverflowFormattedTextArea, FormattedTextArea GetOverflowFormattedTextArea(float x, float y), and FormattedTextArea GetOverflowFormattedTextArea(float x, float y, float height) methods).
The following example illustrates handling overflow text, although, for a more complete example, refer to one of the overloaded methods previously listed. Note that the example uses a do/while loop rather than the HasOverflowText method to determine if a text area has overflow text.
// 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)
In simple situations, where only the overflow text is needed for a TextArea, use the TextArea.GetOverFlowText method.
Obtaining Required Height
Correctly displaying a TextArea or FormattedTextArea requires correctly setting the element's height. Use the GetRequiredHeight method (TextArea.GetRequiredHeight, FormattedTextArea.GetRequiredHeight) to get the height necessary to place all text in the TextArea (or FormattedTextArea) correctly on a page.