Is there anyway to get the overflow from a formatted text area that has been added to a table cell? I have modified an example from the docs. I added the AreaGroup just to see if it would give more control but no luck. I need to know that if I put a formatted text area in a table cell and it extends beyond a page break that I can push it to the next page and not lose it. Is there another way I can do this? I really would like to take advantage of the table functionality because of our printable output needs.
Table2 table = new Table2(0, 0, 500, 700);
// Add columns to the table
table.Columns.Add(100);
table.Columns.Add(400);
string formattedText = GetTextFromFile(MapPath("../Text/FormattedText.txt"));
// This loop populates the table
for (int i = 1; i <= 10; i++)
{
Row2 row = table.Rows.Add(20);
Cell2 cell1 = row.Cells.Add("Row #" + i);
var ta = new FormattedTextArea(
formattedText, 0, 0, 390, 690, FontFamily.Helvetica, 12, false);
float height = ta.GetRequiredHeight();
AreaGroup lineGroup = new AreaGroup(390, height);
lineGroup.Add(ta);
Cell2 cell2 = row.Cells.Add(lineGroup);
cell1.Splittable = true;
cell2.Splittable = true;
}
do
{
Page page = new Page();
document.Pages.Add(page);
page.Elements.Add(table);
table = table.GetOverflowRows();
} while (table != null);
// Save the PDF
document.DrawToWeb("MyDocument.pdf");
Overflow of FormattedTextArea within an AreaGroup
Re: Overflow of FormattedTextArea within an AreaGroup
Support · Mar 14, 2013Hello,
The AreaGroup page element is used to add collection of page elements to the cell of the table. If you are adding a single page element to the cell of the table then you can add that page element directly to the cell.
You will need to build the complete table by adding the FormattedTextArea. If the FormattedTextArea has over flow text then you will need to get the over flow text and build a new row add the over flow text to this new row. Please note that once you add any page element to the cell of the table cell becomes non splittable hence you will need to make sure that you are setting the correct height to the row. Below is the sample code to add single page element to the cell of the table and also to handle the over flow text of the FormattedTextArea.
Document document = new Document();
Table2 table = new Table2(0, 0, 500, 700);
// Add columns to the table
table.Columns.Add(100);
table.Columns.Add(400);
for (int i = 1; i <= 2; i++)
{
string formattedText = File.ReadAllText("C:/Temp/FormattedText.txt");
FormattedTextArea ta = new FormattedTextArea(formattedText, 0, 0, 390, 690, FontFamily.Helvetica, 12, false);
ta.Height = ta.GetRequiredHeight();
// Build the table by adding the FormattedTextArea to cell.
Row2 row = table.Rows.Add(20);
Cell2 cell1 = row.Cells.Add("Row text "+ i);
if (ta.GetRequiredHeight() < table.Height)
{
row.Height = ta.GetRequiredHeight();
}
else
{
ta.Height = table.Height;
}
Cell2 cell2 = row.Cells.Add(ta);
ta = ta.GetOverflowFormattedTextArea();
if (ta != null)
{
while (ta != null)
{
Row2 newRow = table.Rows.Add();
Cell2 newcell1 = newRow.Cells.Add("");
if (ta.GetRequiredHeight() < ta.Height)
{
newRow.Height = ta.GetRequiredHeight();
}
else
{
ta.Height = table.Height;
}
Cell2 newcell2 = newRow.Cells.Add(ta);
ta = ta.GetOverflowFormattedTextArea();
}
}
}
//Adding table to the PDF page.
do
{
Page page = new Page();
document.Pages.Add(page);
page.Elements.Add(table);
table = table.GetOverflowRows();
} while (table != null);
// Save the PDF
document.Draw("C:\\MyDocument.pdf");
Thanks,
ceTe Software Support Team.