public static float GetCellWidth(this PdfPCell cell)
{
if (cell == null) return 0;
var rulesWidth = new List<float>();
var startWidth = cell.PaddingLeft + cell.PaddingRight + 1 + cell.BorderWidth;
var cellWidth = startWidth;
var compositeElements = cell.CompositeElements;
if (compositeElements == null)
{
if (cell.Image != null)
{
cellWidth += cell.Image.Width;
}
if (cell.Phrase != null)
{
cellWidth += GetPhraseWidth(cell.Phrase);
}
if (cell.Table != null)
{
cellWidth += cell.Table.TotalWidth;
}
return cellWidth;
}
foreach (var baseLevel in compositeElements)
{
if (baseLevel is Phrase)
{
cellWidth += GetPhraseWidth((Phrase)baseLevel);
rulesWidth.Add(cellWidth);
cellWidth = startWidth;
}
else if (baseLevel is List)
{
cellWidth = getListWidth(rulesWidth, startWidth, cellWidth, baseLevel);
rulesWidth.Add(cellWidth);
cellWidth = startWidth;
}
else if (baseLevel is PdfGrid)
{
rulesWidth.Add(cellWidth);
cellWidth = startWidth + ((PdfGrid)baseLevel).TotalWidth;
rulesWidth.Add(cellWidth);
cellWidth = startWidth;
}
}
return rulesWidth.Concat(new[] { cellWidth }).Max();
}