/// <summary> /// initialise template /// </summary> /// <param name="template">caller instance</param> /// <param name="tableNode"></param> public TableGenerator(PDFTemplate.PDFTemplate template, XmlNode tableNode) { pdfTemplate = template; if (tableNode != null) { var tableElt = new Table(tableNode.Attributes); XmlNode tableHeadNode = tableNode.SelectSingleNode(".//tablehead"); XmlNode tableLoopNode = tableNode.SelectSingleNode(".//tableloop"); XmlNode tableFootNode = tableNode.SelectSingleNode(".//tablefoot"); this.tableElement = tableElt; tableRowGroupHead = tableHeadNode != null ? BuildTableRowGroup(tableHeadNode) : null; tableRowGroupLoop = tableLoopNode != null ? BuildTableRowGroup(tableLoopNode) : null; tableRowGroupFoot = tableFootNode != null ? BuildTableRowGroup(tableFootNode) : null; } }
/// <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> /// /// </summary> /// <param name="node">tablehead, tableloop, tablefoot</param> /// <returns></returns> private TableRowGroup BuildTableRowGroup(XmlNode node) { TableRowGroup tableRowGroup = new TableRowGroup(); XmlAttributeCollection font = pdfTemplate.DefaultFontAttrs; if (node.FirstChild.Name == "font") { font = node.FirstChild.Attributes; } XmlNodeList tableRowNodes = node.SelectNodes(".//tablerow"); if (tableRowNodes == null) throw new Exception("Table must have rows"); foreach (XmlNode tableRowNode in tableRowNodes) { tableRowGroup.AddTableRow(BuildTableRow(tableRowNode, font)); } return tableRowGroup; }