private static PdfPTable GenerateBatteryVinDashboard(string ProcessDate,int VinID) { BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false); Font times = new Font(bfTimes, 12, Font.ITALIC, Color.RED); Font fontTinyItalic = FontFactory.GetFont("Arial", 7, iTextSharp.text.Font.ITALIC, Color.GRAY); PdfPTable table = new PdfPTable(7); table.WidthPercentage = (70.0f); //relative col widths in proportions - 1/3 and 2/3 // float[] widths = new float[] { 1f, 2f }; float[] colWidths = { 120, 70, 70, 70, 70, 70,70 }; table.SetWidths(colWidths); table.HorizontalAlignment = 1; //leave a gap before and after the table table.SpacingBefore = 20f; table.SpacingAfter = 30f; table.DefaultCell.HorizontalAlignment = 2; //table.DefaultCell.Border = (PdfPCell.BOTTOM_BORDER); table.DefaultCell.GrayFill = 1; table.DefaultCell.Border = (PdfPCell.RECTANGLE); table.DefaultCell.BorderColor = new iTextSharp.text.Color(255, 255, 255); table.DefaultCell.BorderColorBottom = new iTextSharp.text.Color(255, 255, 255); table.DefaultCell.Padding = 4; Color headRowColor = new Color(0, 0, 0); Color headRowFontColor = new Color(255, 255, 255); iTextSharp.text.Font fontIstRow = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.WHITE); // iTextSharp.text.Cell c1 = new iTextSharp.text.Cell(""); string c1Text = "Battery Pack"; PdfPCell cell1 = new PdfPCell(new Phrase(c1Text, fontIstRow)); cell1.HorizontalAlignment = 1; cell1.Border = 0; cell1.GrayFill = 1; cell1.BackgroundColor = headRowColor; table.AddCell(cell1); //c1.UseBorderPadding = false; string c2Text = "dSoC"; PdfPCell cell2 = new PdfPCell(new Phrase(c2Text, fontIstRow)); cell2.HorizontalAlignment = 1; cell2.Border = 0; cell2.GrayFill = 1; cell2.BackgroundColor = headRowColor; table.AddCell(cell2); string c3Text = "I_MIN(A)"; PdfPCell cell3 = new PdfPCell(new Phrase(c3Text, fontIstRow)); cell3.HorizontalAlignment = 1; cell3.Border = 0; cell3.GrayFill = 1; cell3.BackgroundColor = headRowColor; table.AddCell(cell3); string c6Text = "I_MAX(A)"; PdfPCell cell6 = new PdfPCell(new Phrase(c6Text, fontIstRow)); cell6.HorizontalAlignment = 1; cell6.Border = 0; cell6.GrayFill = 1; cell6.BackgroundColor = headRowColor; table.AddCell(cell6); string c7Text = "T_MIN(C)"; PdfPCell cell7 = new PdfPCell(new Phrase(c7Text, fontIstRow)); cell7.HorizontalAlignment = 1; cell7.Border = 0; cell7.GrayFill = 1; cell7.BackgroundColor = headRowColor; table.AddCell(cell7); string c8Text = "T_MAX(C)"; PdfPCell cell8 = new PdfPCell(new Phrase(c8Text, fontIstRow)); cell8.HorizontalAlignment = 1; cell8.Border = 0; cell8.GrayFill = 1; cell8.BackgroundColor = headRowColor; table.AddCell(cell8); string c9Text = "SoC Range"; PdfPCell cell9 = new PdfPCell(new Phrase(c9Text, fontIstRow)); cell9.HorizontalAlignment = 1; cell9.Border = 0; cell9.GrayFill = 1; cell9.BackgroundColor = headRowColor; table.AddCell(cell9); DateTime dtProcessDate; bool IsProcessDate = DateTime.TryParse(ProcessDate, out dtProcessDate); iTextSharp.text.Font fontDynmaicRows = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK); iTextSharp.text.Font fontDynmaicRowsRed = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.RED); iTextSharp.text.Font fontDynmaicRowsNormal = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 8, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK); iTextSharp.text.Font fontDynmaicRowsRedNormal = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 8, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.RED); GetData gd = new GetData(); DataTable dataTable_TempData = new DataTable(); dataTable_TempData = gd.GetDashBoardDataTabular(VinID,dtProcessDate,""); table.HeaderRows = 1; table.DefaultCell.BorderWidth = 1; Color altRow = new Color(242, 242, 242); int i = 0; foreach (DataRow dRow in dataTable_TempData.Rows) { i++; PdfPCell Cell1Hdr = new PdfPCell(new Phrase(dRow[1].ToString().ToUpper(), fontDynmaicRows)); Cell1Hdr.HorizontalAlignment = Element.ALIGN_LEFT; if (i % 2 == 1) { Cell1Hdr.BackgroundColor = altRow; } else { Cell1Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell1Hdr); PdfPCell Cell4Hdr = new PdfPCell(new Phrase(dRow[2].ToString(), fontDynmaicRowsNormal)); Cell4Hdr.HorizontalAlignment = Element.ALIGN_RIGHT; if (i % 2 == 1) { Cell4Hdr.BackgroundColor = altRow; } else { Cell4Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell4Hdr); PdfPCell Cell5Hdr = new PdfPCell(new Phrase(dRow[3].ToString(), fontDynmaicRowsNormal)); Cell5Hdr.HorizontalAlignment = Element.ALIGN_RIGHT; if (i % 2 == 1) { Cell5Hdr.BackgroundColor = altRow; } else { Cell5Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell5Hdr); PdfPCell Cell6Hdr = new PdfPCell(new Phrase(dRow[4].ToString(), fontDynmaicRowsNormal)); Cell6Hdr.HorizontalAlignment = Element.ALIGN_RIGHT; if (i % 2 == 1) { Cell6Hdr.BackgroundColor = altRow; } else { Cell6Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell6Hdr); PdfPCell Cell7Hdr = new PdfPCell(new Phrase(dRow[5].ToString(), fontDynmaicRowsNormal)); Cell7Hdr.HorizontalAlignment = Element.ALIGN_RIGHT; if (i % 2 == 1) { Cell7Hdr.BackgroundColor = altRow; } else { Cell7Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell7Hdr); PdfPCell Cell8Hdr = new PdfPCell(new Phrase(dRow[6].ToString(), fontDynmaicRowsNormal)); Cell8Hdr.HorizontalAlignment = Element.ALIGN_RIGHT; if (i % 2 == 1) { Cell8Hdr.BackgroundColor = altRow; } else { Cell8Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell8Hdr); PdfPCell Cell9Hdr = new PdfPCell(new Phrase(dRow[7].ToString(), fontDynmaicRowsNormal)); Cell9Hdr.HorizontalAlignment = Element.ALIGN_RIGHT; if (i % 2 == 1) { Cell9Hdr.BackgroundColor = altRow; } else { Cell9Hdr.BackgroundColor = Color.WHITE; } table.AddCell(Cell9Hdr); } return table; }