Posted by a ceTe Software moderator
Hello,
You will need to set some height to the FormattedTextArea at the time of creating object of it and you can dynamically change the height in the further process using Height property of the FormattedTextArea. You can get the required height to fit the contents using GetRequiredHeight method and you can compare this height with the page height and change it accordingly. Below is sample code to add the text contents using FormattedTextArea.
Document document = new Document();
String paragraph = "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. ";
// Define Formatted Text Area
FormattedTextArea formattedTextArea = new FormattedTextArea(paragraph, 0, 0, 256, 400, ceTe.DynamicPDF.FontFamily.Helvetica, 12, false);
//Setting desired height to fit the contents.
formattedTextArea.Height = formattedTextArea.GetRequiredHeight();
do
{
Page page = new Page();
document.Pages.Add(page);
if (formattedTextArea.GetRequiredHeight() > page.Dimensions.Body.Height)
{
formattedTextArea.Height = page.Dimensions.Body.Height;
}
else
{
formattedTextArea.Height = formattedTextArea.GetRequiredHeight();
}
page.Elements.Add(formattedTextArea);
formattedTextArea = formattedTextArea.GetOverflowFormattedTextArea();
}
while (formattedTextArea != null);
document.Draw(@"C:\MyDocument.pdf");
Thanks,
ceTe Software Support Team.