Hi Team,
I have an requirement to render html content in table cell. I added one row and cell in same row.
Code snippet:
Row2 row = table.Rows.Add();
Cell2 tblCell = row.Cells.Add(string.Empty, 1, 1);
FormattedTextArea cellTextArea = new FormattedTextArea("<br>TestData1 TestData2 TestData3 TestData4
TestData1 TestData2 TestData3 TestData4
TestData1 TestData2 TestData3 TestData4
TestData1 TestData2 TestData3 TestData4
</br> ", 0, 0,160, 40, FontFamily.Times, 12, false
);
cellTextArea.Height = cellTextArea.GetRequiredHeight();
tblCell.Row.Height = cellTextArea.Height;
tblCell.Element = cellTextArea;
Here I added FormattedTextArea and assigned Html content on same, after that trying to assign in Cell.Element.
Now content is going out of table row. I tried to set table row height but its not reflecting on PDF.
So after rendering some of the content going out of table row.
Please provide the solution for it.
Thanks & Regards,
Chandan Singh
FormattedTextArea content going out of TableRow
Re: FormattedTextArea content going out of TableRow
Support · Aug 9, 2021Hi Chandan,
When a page element is added to cell, it becomes non splitable. You will need to hande the splitting and dimensions of the Row2 object as per the page element's dimensions.
Here is a code sample to add FormattedTextArea to a cell of Table2 object and handling overflow.
Document document = new Document();
Table2 table = new Table2(0, 0, 255, 0);
// Add columns to the table
Page page1 = new Page();
table.Columns.Add(152);
table.Columns.Add(100);
float occupiedHeight = table.Y;
string text = "Test Text for FTA.";
for (int i = 0; i < 8; i++)
{
text = text + text;
}
FormattedTextAreaStyle fontstyle = new FormattedTextAreaStyle(ceTe.DynamicPDF.FontFamily.Helvetica, 10, true);
FormattedTextArea area = new FormattedTextArea(text, 0, 0, 150, 0, fontstyle);
area.Height = area.GetRequiredHeight();
// Build the table by adding the FormattedTextArea to cell.
Row2 row = table.Rows.Add(20);
if (area.GetRequiredHeight() < page1.Dimensions.Body.Height - occupiedHeight)
{
area.Height = area.GetRequiredHeight();
}
else
{
area.Height = page1.Dimensions.Body.Height - occupiedHeight;
}
Cell2 cell2 = row.Cells.Add(area);
Cell2 cell21 = row.Cells.Add("Row1Cell2");
row.Height = area.Height;
area = area.GetOverflowFormattedTextArea();
while (area != null)
{
Row2 newRow = table.Rows.Add();
area.Height = area.GetRequiredHeight();
if (area.GetRequiredHeight() < page1.Dimensions.Body.Height)
{
area.Height = area.GetRequiredHeight();
}
else
{
area.Height = page1.Dimensions.Body.Height;
}
Cell2 newcell2 = newRow.Cells.Add(area);
Cell2 newcell22 = newRow.Cells.Add("");
newRow.Height = area.Height;
area = area.GetOverflowFormattedTextArea();
}
//Adding more rows to table.
for (int i = 2; i <= 20; i++)
{
Row2 row2 = table.Rows.Add(20);
row2.Cells.Add("Row #" + i);
row2.Cells.Add("Item");
}
//Adding table to the PDF page.
do
{
Page page = new Page();
document.Pages.Add(page);
if (table.GetRequiredHeight() < page.Dimensions.Body.Height)
{
table.Height = table.GetRequiredHeight();
}
else
{
table.Height = page.Dimensions.Body.Height;
}
page.Elements.Add(table);
table = table.GetOverflowRows();
} while (table != null);
// Save the PDF
document.Draw(@"C:\Temp\MyDocument.pdf");
Thanks,
ceTe Software Support Team