public static PdfGrid CloneMainTableStructure(DocumentPreferences pageSetup, IList<ColumnAttributes> pdfColumnsDefinitions)
{
if (pageSetup.GroupsPreferences == null || pageSetup.GroupsPreferences.GroupType == GroupType.HideGroupingColumns)
{
pdfColumnsDefinitions = pdfColumnsDefinitions.Where(x => x.IsVisible && !x.IncludeInGrouping).OrderBy(x => x.Order).ToList();
}
if (pageSetup.GroupsPreferences != null && pageSetup.GroupsPreferences.GroupType == GroupType.IncludeGroupingColumns)
{
pdfColumnsDefinitions = pdfColumnsDefinitions.Where(x => x.IsVisible || x.IncludeInGrouping).OrderBy(x => x.Order).ToList();
}
var widths = pageSetup.PagePreferences.RunDirection == PdfRunDirection.LeftToRight
? pdfColumnsDefinitions.OrderBy(x => x.Order).Select(x => x.Width).ToArray()
: pdfColumnsDefinitions.OrderBy(x => x.Order).Select(x => x.Width).Reverse().ToArray();
if (pageSetup.PagePreferences.RunDirection == null)
pageSetup.PagePreferences.RunDirection = PdfRunDirection.LeftToRight;
var mainTable = new PdfGrid(widths.Length)
{
RunDirection = (int)pageSetup.PagePreferences.RunDirection,
WidthPercentage = pageSetup.MainTablePreferences.WidthPercentage,
SplitLate = pageSetup.MainTablePreferences.SplitLate,
SpacingAfter = pageSetup.MainTablePreferences.SpacingAfter,
SpacingBefore = pageSetup.MainTablePreferences.SpacingBefore,
KeepTogether = pageSetup.MainTablePreferences.KeepTogether,
SplitRows = pageSetup.MainTablePreferences.SplitRows
};
switch (pageSetup.MainTablePreferences.ColumnsWidthsType)
{
case TableColumnWidthType.Relative:
if(pageSetup.MainTablePreferences.TableType == TableType.NormalTable)
mainTable.SetWidths(widths);
break;
case TableColumnWidthType.Absolute:
if (pageSetup.MainTablePreferences.TableType == TableType.NormalTable)
mainTable.SetTotalWidth(widths);
break;
case TableColumnWidthType.FitToContent:
break;
case TableColumnWidthType.EquallySized:
break;
}
return mainTable;
}