/// <summary> /// Draws table row group /// </summary> /// <param name="table"></param> /// <param name="tableRowGroup"></param> /// <param name="data"></param> protected void DrawTableRowGroup( ref PdfPTable table, TableRowGroup tableRowGroup, IDictionary data) { //int count = 0; foreach (TableRow tableRow in tableRowGroup.TableRows) { bool haveSize = DrawTableRow(table, tableRow, data); //Console.WriteLine("_drawTableRowGroup count: " + count + " haveSize: " + haveSize); if (!haveSize) { //Console.WriteLine("_drawTableRowGroup in no more size"); //1. draw the current table to pdf pdfDrawer.NextRow(1, DocumentGroup.Table); PDFDrawItextSharp.PDFDrawItextSharp pdfDraw = (PDFDrawItextSharp.PDFDrawItextSharp)pdfDrawer; pdfDraw.DrawTable(table, pdfDraw.Current_x, pdfDraw.Current_y); //2. move pdf to next page pdfTemplate.NextPage(); pdfTemplate.DrawHeader(); //Console.WriteLine("Call nextPage, DrawHeader()"); //3. recreate table with the header table = DrawTableHead(); //Console.WriteLine("call _drawTableHead(), table.totalheight: " + table.TotalHeight); //4. add the current row to the new table DrawTableRow(table, tableRow, data); } //count++; } }
/// <summary> /// Render /// </summary> public void DrawTable(TableData data, IPDFDraw drawer) { tableData = data; pdfDrawer = drawer; if (tableData.LoopData != null) { PdfPTable table = DrawTableHead(); DrawTableLoop(ref table); DrawTableFoot(ref table); if (table.Rows.Count > 0) { var pdfDraw = (PDFDrawItextSharp.PDFDrawItextSharp)pdfDrawer; pdfDrawer.NextRow(1, DocumentGroup.Table); pdfDraw.DrawTable(table, pdfDraw.Current_x, pdfDraw.Current_y); pdfDraw.NextRow(table.TotalHeight, DocumentGroup.Table); } } }
/// <summary> /// Render /// </summary> public void DrawTable(TableData data, IPDFDraw drawer) { tableData = data; pdfDrawer = drawer; // Dynamic columns init: add dynamic columns model if (tableData.DynamicColumns != null && tableData.DynamicColumns.Any()) { // define dynamic table object attributes var tableAttributes = tableElement.Attributes; XmlNode cellPerRowAttr = tableAttributes.GetNamedItem("cellperrow"); XmlNode cellwidthAttr = tableAttributes.GetNamedItem("cellwidth"); if (cellPerRowAttr != null && cellwidthAttr != null) { var cellPerRow = IntHelper.TryParseDefault(cellPerRowAttr.Value, -1); cellPerRowAttr.Value = (cellPerRow + tableData.DynamicColumns.Count).ToString(); cellwidthAttr.Value = cellwidthAttr.Value + (string.IsNullOrEmpty(cellwidthAttr.Value) ? "" : ",") + string.Join(",", tableData.DynamicColumns.Select(x => x.CellWidth)); } foreach (var dynamicColumn in tableData.DynamicColumns) { // nconvert templates to xmlnode element var nodeHead = string.IsNullOrEmpty(dynamicColumn.HeaderTemplate) ? null : GenerateNode(dynamicColumn.HeaderTemplate); var nodeData = GenerateNode(dynamicColumn.DataTemplate); var nodeFoot = string.IsNullOrEmpty(dynamicColumn.FooterTemplate) ? null : GenerateNode(dynamicColumn.FooterTemplate); // define dynamic table head items if (nodeHead != null) { tableRowGroupHead.TableRows.ForEach(x => { x.AddTableCell(BuildTableCell(nodeHead, fontHead)); }); } // define dynamic tableloop items tableRowGroupLoop.TableRows.ForEach(x => { x.AddTableCell(BuildTableCell(nodeData, fontLoop)); }); // define dynamic table foot items if (nodeFoot != null) { tableRowGroupFoot.TableRows.ForEach(x => { x.AddTableCell(BuildTableCell(nodeFoot, fontFoot)); }); } } } if (tableData.LoopData != null) { PdfPTable table = DrawTableHead(); DrawTableLoop(ref table); DrawTableFoot(ref table); if (table.Rows.Count > 0) { var pdfDraw = (PDFDrawItextSharp.PDFDrawItextSharp)pdfDrawer; pdfDrawer.NextRow(1, DocumentGroup.Table); pdfDraw.DrawTable(table, pdfDraw.Current_x, pdfDraw.Current_y); pdfDraw.NextRow(table.TotalHeight, DocumentGroup.Table); } } }