private MigraDoc.DocumentObjectModel.Tables.Table AddTable(IPdfStyling pdfStyling, Section section) { // This is a little bit faky, otherwise we can't add spaces before and after table if (this._spaceBefore > 0 || this._spaceAfter > 0) { IPdfElement pdfSpace = new PdfSpace(this._spaceBefore, this._spaceAfter); pdfSpace.Render(pdfStyling: pdfStyling, section: section); } // Add table to the section MigraDoc.DocumentObjectModel.Tables.Table table = section.AddTable(); // This is a little bit faky, otherwise we can't add spaces before and after table if (this._spaceBefore > 0 || this._spaceAfter > 0) { IPdfElement pdfSpace = new PdfSpace(this._spaceBefore, this._spaceAfter); pdfSpace.Render(pdfStyling: pdfStyling, section: section); } //THead (and Columns) // Calculate widths if necessary double[] widths = TableExtensions.CalculateColumnWidths( pdfStyling: pdfStyling, document: section.Document, tHead: this.THead, tBody: this.TBody, fitToDocument: _fitToDocument); // Create columns from THead Column column; for (int c = 0; c < this.THead.Count; c++) { column = table.AddColumn(new Unit(widths[c])); column.Format.Alignment = this.THead[c].Alignment.GetAlignment(); } // Create the header of the table Row thead; if (this.THead.Any(o => string.IsNullOrWhiteSpace(o.Text.Trim())) == false) { //HINT: If an error appears here because you did not added PdfTableHeaderCells -> you have to add but with empty strings :-) thead = table.AddRow(); thead.TopPadding = Unit.FromPoint(5); //titleRow.BottomPadding = Unit.FromPoint(5); thead.HeadingFormat = true; for (int i = 0; i < this.THead.Count; i++) { AddText( pdfStyling: pdfStyling, pdfCell: this.THead[i], cell: thead.Cells[i]); thead.Cells[i].VerticalAlignment = VerticalAlignment.Top; thead.Cells[i].Style = PdfStyleNames.Table.THead; } } //TBody for (int i = 0; i < this.TBody.Count; i++) { AddCell( pdfStyling: pdfStyling, table: table, pdfRow: this.TBody[i], isTFoot: false); } //TFoot for (int i = 0; i < this.TFoot.Count; i++) { AddCell( pdfStyling: pdfStyling, table: table, pdfRow: this.TFoot[i], isTFoot: true); } return(table); }