private static void addSimpleRowCell(PdfGrid table, Action<CellRowData, CellBasicProperties> cellDataItem) { var cellBasicProperties = new CellBasicProperties { BorderColor = BaseColor.BLACK, HorizontalAlignment = HorizontalAlignment.Center, RunDirection = PdfRunDirection.LeftToRight, FontColor = new BaseColor(Color.Black.ToArgb()), BackgroundColor = BaseColor.WHITE, PdfFontStyle = DocumentFontStyle.Normal }; var cellData = new CellRowData { Value = string.Empty, FormattedValue = string.Empty }; if (cellDataItem != null) cellDataItem(cellData, cellBasicProperties); if (cellData.CellTemplate == null) cellData.CellTemplate = new TextBlockField(); var cellAttributes = new CellAttributes { BasicProperties = cellBasicProperties, RowData = cellData }; table.AddCell(cellAttributes.CreateSafePdfPCell(cellData.CellTemplate)); }
// Public Methods (7) /// <summary> /// Adds a new PdfPCell to the MainTable /// </summary> /// <param name="backgroundColor"></param> /// <param name="foreColor"></param> /// <param name="rawData"></param> /// <param name="columnNumber"></param> /// <param name="pdfRowType"></param> /// <param name="pdfCellType"></param> /// <param name="rowValues"></param> /// <param name="horizontalAlignment"></param> /// <param name="pdfFontStyle"></param> /// <param name="rotation"></param> /// <param name="setItemTemplate"></param> /// <param name="colSpan"></param> /// <returns></returns> public CellAttributes AddGeneralCell( BaseColor backgroundColor, BaseColor foreColor, object rawData, int columnNumber, RowType pdfRowType, CellType pdfCellType, IList<CellData> rowValues = null, HorizontalAlignment horizontalAlignment = HorizontalAlignment.None, DocumentFontStyle pdfFontStyle = DocumentFontStyle.None, int rotation = 0, bool setItemTemplate = false, int colSpan = 1) { var col = SharedData.PdfColumnsAttributes[columnNumber]; var cellData = new CellAttributes { RowData = new CellRowData { TableRowData = rowValues, Value = rawData, PdfRowType = pdfRowType, ColumnNumber = columnNumber }, SharedData = new CellSharedData { PdfColumnAttributes = col, DataRowNumber = CurrentRowInfoData.LastOverallDataRowNumber, GroupNumber = CurrentRowInfoData.LastGroupRowNumber, PdfDoc = SharedData.PdfDoc, PdfWriter = SharedData.PdfWriter, SummarySettings = SharedData.SummarySettings, Template = SharedData.Template }, ItemTemplate = setItemTemplate ? col.ColumnItemsTemplate : null, BasicProperties = new CellBasicProperties { PdfFont = SharedData.PdfFont, Rotation = rotation, PdfFontStyle = (pdfFontStyle == DocumentFontStyle.None) ? DocumentFontStyle.Normal : pdfFontStyle, BackgroundColor = backgroundColor, BorderColor = SharedData.Template.CellBorderColor, FontColor = foreColor, RunDirection = SharedData.PageSetup.PagePreferences.RunDirection, ShowBorder = SharedData.Template.ShowGridLines, HorizontalAlignment = (horizontalAlignment == HorizontalAlignment.None) ? col.CellsHorizontalAlignment : horizontalAlignment, FixedHeight = pdfRowType == RowType.DataTableRow ? col.FixedHeight : 0, MinimumHeight = pdfRowType == RowType.DataTableRow ? col.MinimumHeight : 0 } }; if (SharedData.MainTableEvents != null) SharedData.MainTableEvents.CellCreated(new EventsArguments { PdfDoc = SharedData.PdfDoc, PdfWriter = SharedData.PdfWriter, Cell = cellData, CellType = pdfCellType, RowType = pdfRowType, ColumnNumber = columnNumber, ColumnCellsSummaryData = SharedData.ColumnCellsSummaryData, PreviousTableRowData = CurrentRowInfoData.PreviousTableRowData, PageSetup = SharedData.PageSetup, PdfFont = SharedData.PdfFont, PdfColumnsAttributes = SharedData.PdfColumnsAttributes }); var cell = cellData.CreateSafePdfPCell(new TextBlockField()); cell.CellEvent = new MainTableCellsEvent(cellData) { SummaryCellsData = SharedData.ColumnCellsSummaryData, IsGroupingEnabled = SharedData.IsGroupingEnabled, CurrentRowInfoData = CurrentRowInfoData }; if (colSpan > 1) cell.Colspan = colSpan; MainTable.AddCell(cell); if (SharedData.MainTableEvents != null) SharedData.MainTableEvents.CellAdded(new EventsArguments { PdfDoc = SharedData.PdfDoc, PdfWriter = SharedData.PdfWriter, Cell = cellData, CellType = pdfCellType, RowType = pdfRowType, ColumnNumber = columnNumber, ColumnCellsSummaryData = SharedData.ColumnCellsSummaryData, PreviousTableRowData = CurrentRowInfoData.PreviousTableRowData, PageSetup = SharedData.PageSetup, PdfFont = SharedData.PdfFont, PdfColumnsAttributes = SharedData.PdfColumnsAttributes }); return cellData; }
/// <summary> /// Adds a SummaryRow to an existing PdfGrid /// </summary> /// <param name="table">An existing PdfGrid</param> /// <param name="pdfColumnsDefinitions">List of the PdfColumnAttributes</param> /// <param name="summaryProperty">Sets the location of summary cell's data</param> /// <param name="labelProperty">Sets the location of summary cell's label</param> /// <param name="summaryCell">SummaryCell's Attributes</param> /// <param name="labelCell">LabelCell's Attributes</param> /// <param name="emptyCell">The other not in use cell's Attributes</param> /// <param name="itemsTemplate">Default ItemsTemplate</param> public static void AddSummaryRow(this PdfGrid table, IList<ColumnAttributes> pdfColumnsDefinitions, string summaryProperty, string labelProperty, CellAttributes summaryCell, CellAttributes labelCell, CellAttributes emptyCell, IColumnItemsTemplate itemsTemplate) { foreach (var col in pdfColumnsDefinitions) { if (col.PropertyName == summaryProperty) { table.AddCell(summaryCell.CreateSafePdfPCell(itemsTemplate)); } else if (col.PropertyName == labelProperty) { table.AddCell(labelCell.CreateSafePdfPCell(itemsTemplate)); } else { table.AddCell(emptyCell.CreateSafePdfPCell(itemsTemplate)); } } }