private void AddTableData(bool lastLineBold) { // Set the table to be the entire width of the page double width; double height; if (DocumentSettings.Orientation == Orientation.Landscape) { width = Document.DefaultPageSetup.PageHeight.Centimeter; height = Document.DefaultPageSetup.PageWidth.Centimeter; } else { height = Document.DefaultPageSetup.PageHeight.Centimeter; width = Document.DefaultPageSetup.PageWidth.Centimeter; } var leftMargin = Document.DefaultPageSetup.LeftMargin.Centimeter; var rightMargin = Document.DefaultPageSetup.RightMargin.Centimeter; // Make all columns the same length (for now) var table = new Table(); var colSize = (width - leftMargin - rightMargin) / TableHeadings.Keys.Count; // Give the table a nice border. table.Borders.Width = 0.75; // Add enought columns for (var i = 0; i < TableHeadings.Keys.Count; i++) { table.AddColumn(Unit.FromCentimeter(colSize)); } var row = table.AddRow(); row.Shading.Color = Colors.DarkGray; row.HeadingFormat = true; row.Format.Font.Bold = true; row.Format.Font.Size = 12; row.Borders.Width = 0; row.Height = Unit.FromPoint(15); for (var i = 0; i < TableHeadings.Keys.Count; i++) { var heading = TableHeadings.ElementAt(i); var cell = row.Cells[i]; cell.AddParagraph(heading.Value); } for (var i = 0; i < TableContent.Count; i++) { var rowData = TableContent.ElementAt(i); row = table.AddRow(); if (rowData == null) // Empty row { row.Borders.Width = 0; continue; } row.Style = StyleNames.Normal; row.Borders.Width = 0; row.Borders.Top.Width = 0.75; if (lastLineBold && i == (TableContent.Count - 1)) { row.Format.Font.Bold = true; row.Borders.Width = 0; } for (var j = 0; j < TableHeadings.Keys.Count; j++) { var headingKey = TableHeadings.Keys.ElementAt(j); var cell = row.Cells[j]; //cell.MergeRight --ColSpan cell.AddParagraph(rowData[headingKey]); } } //Don't need this, 'table.Borders.Width' above set borders. //table.SetEdge(0, 0, 2, 100 + 1, Edge.Interior | Edge.Box, BorderStyle.Single, 1, Colors.Black); Document.LastSection.Add(table); }