We’re trying to implement our own text truncation that adds ellipsis ("…") to the end of a cell that may textwrap similar to this previous thread. We have something working with the Cell.Width and TextState.MeasureString functions, but we noticed that Cell.Width returns an incorrect value if percentages are used in the columnwidths property of the table. Additionally, the table.GetWidth() function seems to cause the first column to take up the whole page. This becomes an issue because we can have some nested tables as well and we’re unable to get the actual cell width to see if we need to truncate the text.
Document doc = new Document();
Page page = doc.Pages.Add();
page.PageInfo.Width = PageSize.PageLetter.Width;
page.PageInfo.Height = PageSize.PageLetter.Height;
page.PageInfo.Margin = new MarginInfo(27, 27, 27, 27);
var table1 = new Aspose.Pdf.Table()
{
ColumnWidths = “80 80”,
DefaultCellPadding = new MarginInfo(5, 1, 5, 1),
IsBordersIncluded = true,
Broken = TableBroken.Vertical
};
var row1 = table1.Rows.Add();
var cell1 = row1.Cells.Add();
var tfragment1 = new TextFragment(“Sample Text Fragment1”);
cell1.Paragraphs.Add(tfragment1);
var cell2 = row1.Cells.Add();
var tfragment2 = new TextFragment(“Sample Text Fragment2”);
cell2.Paragraphs.Add(tfragment2);
var table2 = new Aspose.Pdf.Table()
{
ColumnWidths = “50% 50%”,
DefaultCellPadding = new MarginInfo(5, 1, 5, 1),
IsBordersIncluded = true,
Broken = TableBroken.Vertical
};
var row2 = table2.Rows.Add();
var cell3 = row2.Cells.Add();
cell3.Paragraphs.Add(tfragment1);
var cell4 = row2.Cells.Add();
cell4.Paragraphs.Add(tfragment2);
var nestedTable1 = new Aspose.Pdf.Table()
{
ColumnWidths = “50% 50%”,
DefaultCellPadding = new MarginInfo(5, 1, 5, 1),
IsBordersIncluded = true,
Broken = TableBroken.Vertical
};
var nestedTable2 = new Aspose.Pdf.Table()
{
ColumnWidths = “50% 50%”,
DefaultCellPadding = new MarginInfo(5, 1, 5, 1),
IsBordersIncluded = true,
Broken = TableBroken.Vertical
};
var innerRow = nestedTable2.Rows.Add();
var innerCell1 = innerRow.Cells.Add();
innerCell1.Paragraphs.Add(tfragment1);
var innerCell2 = innerRow.Cells.Add();
innerCell2.Paragraphs.Add(tfragment1);
var outerRow = nestedTable1.Rows.Add();
var outerCell1 = outerRow.Cells.Add();
cell3.Paragraphs.Add(nestedTable2);
var outerCell2 = outerRow.Cells.Add();
cell4.Paragraphs.Add(nestedTable2);
page.Paragraphs.Add(table1);
page.Paragraphs.Add(table2);
page.Paragraphs.Add(nestedTable1);
table1.GetWidth();
//table2.GetWidth();
Debug.Assert(cell1.Width == 80);
Debug.Assert(cell2.Width == 80);
//Debug.Assert(cell3.Width == 270.5);
//Debug.Assert(cell4.Width == 270.5);
doc.Save(“cellwidthbug.pdf”);