/// <summary> /// Create a PDF representation of the table /// </summary> /// <param name="inputTable"> /// The <c>Table</c> to parse /// </param> /// <returns> /// A PDF Table /// </returns> private static PdfPTable CreatePdf(Table inputTable) { if (inputTable.Children.Count > 0 && inputTable.Children[0] != null) { TableRow firstRow = inputTable.GetRow(0); int cols = firstRow.CellCount; var table = new PdfPTable(cols); foreach (TableRow row in inputTable.Children) { if (row != null) { foreach (TableCell tableCell in row.Children) { if (tableCell != null) { var cell = new PdfPCell(new Paragraph(tableCell.Text)) { Rowspan = tableCell.RowSpan, Colspan = tableCell.ColumnSpan, Padding = 3.0f, HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, BorderColor = _borderColor, BackgroundColor = _defaultBackgroundColor }; cell.Phrase.Font.SetFamily("Helvetica"); cell.Phrase.Font.SetStyle(Font.NORMAL); if (tableCell.HasClass(HtmlClasses.SliceKeyTitle)) { cell.Phrase.Font.SetStyle(Font.BOLD); cell.BackgroundColor = _keyValueBackgroundColor; cell.HorizontalAlignment = Element.ALIGN_RIGHT; } else if (tableCell.HasClass(HtmlClasses.VerticalKeyTitle) || tableCell.HasClass(HtmlClasses.HorizontalKeyTitle)) { cell.Phrase.Font.SetStyle(Font.BOLD); cell.BackgroundColor = _keyValueBackgroundColor; } else if (tableCell.HasClass(HtmlClasses.HorizontalKeyValue) || tableCell.HasClass(HtmlClasses.VerticalKeyValue)) { cell.BackgroundColor = _keyValueBackgroundColor; } // TODO handle this some other way // if (td.Attr.TryGetValue("class", out clazz) && !String.IsNullOrEmpty(clazz)) { // if ("keytitle".Contains(clazz.Substring(1))) { // cell.Phrase.Font.SetStyle(Font.BOLD); // cell.BackgroundColor = new BaseColor(0xDF, 0xEF, 0xFC); // if (clazz.Contains("skeytitle")) { // cell.HorizontalAlignment = Element.ALIGN_RIGHT; // } // } // else if (clazz.Contains("keyvalue")) { // cell.BackgroundColor = new BaseColor(0xDF, 0xEF, 0xFC); // } // } table.AddCell(cell); } } } } return table; } return null; }