public static void AutoResizeTableColumns(this PdfGrid table)
{
if (table == null) return;
var currentRowWidthsList = new List<float>();
var previousRowWidthsList = new List<float>();
foreach (var row in table.Rows)
{
currentRowWidthsList.Clear();
currentRowWidthsList.AddRange(row.GetCells().Select(cell => cell.GetCellWidth()));
if (!previousRowWidthsList.Any())
{
previousRowWidthsList = new List<float>(currentRowWidthsList);
}
else
{
for (int i = 0; i < previousRowWidthsList.Count; i++)
{
if (previousRowWidthsList[i] < currentRowWidthsList[i])
previousRowWidthsList[i] = currentRowWidthsList[i];
}
}
}
if (previousRowWidthsList.Any())
table.SetTotalWidth(previousRowWidthsList.ToArray());
}