public static void GeneratePDFDashboardData(DataSet tables, Schedule report, Document pdfDoc) { pdfDoc.Open(); Font link = FontFactory.GetFont("TIMES_ROMAN", 10, Font.BOLD, BaseColor.BLACK); Anchor click = new Anchor("Report Name:" + "-" + report.ReportName, link); click.Reference = "www.sentelsolutions.com"; Paragraph p1 = new Paragraph(); p1.Add(click); pdfDoc.Add(p1); //pdfDoc.Add(new iTextSharp.text.Paragraph("Report Name:" + "-" + report.ReportName, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 10, iTextSharp.text.Font.BOLD, BaseColor.BLACK))); pdfDoc.Add(new iTextSharp.text.Paragraph(" ")); pdfDoc.Add(new iTextSharp.text.Paragraph("Schedule Name:" + "-" + report.Selectedname, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 9, iTextSharp.text.Font.BOLD, BaseColor.BLACK))); pdfDoc.Add(new iTextSharp.text.Paragraph(" ")); pdfDoc.Add(new iTextSharp.text.Paragraph("Date range:" + report.ListofFilters.Split('=', ',')[5].TrimStart('\'').TrimEnd('\'') + " TO " + report.ListofFilters.Split('=', ',')[7].TrimStart('\'').TrimEnd('\''), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 9, iTextSharp.text.Font.BOLD, BaseColor.BLACK))); switch (report.ReportName) { case "Operator Performance": int repid = 0; List <iTextSharp.text.Image> ImgList = new List <Image>(); foreach (DataRow dr in tables.Tables[0].Rows) { GraphicalReport.GenerateCircularGauge("Z:\\inetpub\\wwwroot\\proimages\\" + report.Selectedname + "-" + report.ReportName + DateTime.Now.ToString("ddMMyy") + repid.ToString() + "-" + report.ID + ".png", Convert.ToDouble(dr["Target"]), Convert.ToDouble(dr["_Avg"]), Convert.ToDouble(dr["_Bad"]), Convert.ToDouble(dr["Ring"]), dr[0].ToString(), dr["_Back"].ToString()); ImgList.Add(iTextSharp.text.Image.GetInstance("Z:\\inetpub\\wwwroot\\proimages\\" + report.Selectedname + "-" + report.ReportName + DateTime.Now.ToString("ddMMyy") + repid.ToString() + "-" + report.ID + ".png")); repid++; } List <int> numbers = new List <int>(); for (int i = 3; i < ImgList.Count; i += 3) { numbers.Add(i); } numbers.Add(numbers.Last() + 3); for (int i = ImgList.Count(); i <= numbers.Last(); i++) { ImgList.Add(iTextSharp.text.Image.GetInstance("Z:\\inetpub\\wwwroot\\proimages\\EmptySpace.png")); } var table1 = new PdfPTable(3); //table1 table1.HorizontalAlignment = Element.ALIGN_MIDDLE; table1.SpacingBefore = 20; table1.DefaultCell.Border = 0; //table1.WidthPercentage = 20; foreach (Image img in ImgList) { PdfPCell cell = new PdfPCell(img); table1.AddCell(cell); } pdfDoc.Add(table1); PDFReports.BindPDFdataWithKPIIndication(pdfDoc, tables.Tables[0], tables.Tables[0].Columns.Cast <DataColumn>().Where(s => !s.ColumnName.Contains("_") && s.ColumnName != "DrillDown").Select(x => x.ColumnName).ToList(), GenerateReports.Listoftotals(report.Totals), "Ring", "_Back"); break; } pdfDoc.Close(); }
// This method will create PDF file and inserts into portfolio reports..... public static void GeneratePDFReport(Schedule report) { // this check is for departmental reports DataSet tables = ExtecuteReport(report); if (tables.Tables[0].Rows.Count >= 1 || report.StoredProcedureName.Contains("spSelectDepartmentalBreakdownreportLevel")) { // create a file with the name string file = @"c:\\temp\\ " + report.Selectedname + " - " + report.ReportName + DateTime.Now.ToString("ddMMyy") + "-" + report.ID + ".pdf"; // creating a pdf file iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(PageSize.A4, 5, 5, 10, 10); //System.IO.MemoryStream mStream = new System.IO.MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(pdfDoc, new FileStream(file, FileMode.Create)); try { if (Otherreports(report.ReportingSection) == false) { pdfDoc.Open(); pdfDoc.Add(new iTextSharp.text.Paragraph("Report Name:" + "-" + report.ReportName, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 10, iTextSharp.text.Font.BOLD, BaseColor.BLACK))); pdfDoc.Add(new iTextSharp.text.Paragraph(" ")); pdfDoc.Add(new iTextSharp.text.Paragraph("Schedule Name:" + "-" + report.Selectedname, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 9, iTextSharp.text.Font.BOLD, BaseColor.BLACK))); pdfDoc.Add(new iTextSharp.text.Paragraph(" ")); pdfDoc.Add(new iTextSharp.text.Paragraph("Date range:" + report.ListofFilters.Split('=', ',')[5].TrimStart('\'').TrimEnd('\'') + " TO " + report.ListofFilters.Split('=', ',')[7].TrimStart('\'').TrimEnd('\''), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 9, iTextSharp.text.Font.BOLD, BaseColor.BLACK))); //pdfDoc.Add(new iTextSharp.text.Paragraph(" Date range: " + " -" report.ListofFilters.Split('=', ',')[5].TrimStart('\'').TrimEnd('\'') + " TO " + report.ListofFilters.Split('=', ',')[7].TrimStart('\'').TrimEnd('\''))); pdfDoc.Add(new iTextSharp.text.Paragraph(" ")); if (report.StoredProcedureName.Contains("spSelectDepartmentalBreakdownreportLevel")) { // PDFReports.BindPDFdata(pdfDoc, tables.Tables[0], GetColumns(report.Columns), Listoftotals(report.Totals)); PDFReports.Departmentalreport(pdfDoc, tables, GetColumns(report.Columns), report.ListofFilters.Split('=', ',')[93], GetLevels(tables), Listoftotals(report.Totals)); } else { if (tables.Tables.Count >= 3) { int i = 0; foreach (DataTable dt in tables.Tables) { List <string> column = new List <string>(); foreach (DataColumn dc in dt.Columns) { column.Add(dc.ColumnName); } pdfDoc.Add(new iTextSharp.text.Paragraph(report.Columns.Split(',')[i], new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 9, iTextSharp.text.Font.BOLD, BaseColor.BLACK))); pdfDoc.Add(new iTextSharp.text.Paragraph(" ")); PDFReports.BindPDFdata(pdfDoc, dt, column, Listoftotals(report.Totals)); pdfDoc.Add(new iTextSharp.text.Paragraph(" ")); i++; } } else { PDFReports.BindPDFdata(pdfDoc, tables.Tables[0], GetColumns(report.Columns), Listoftotals(report.Totals)); } } if (report.GraphBindings != string.Empty) { int repid = 0; foreach (string graph in report.GraphBindings.Split('-')) { GraphicalReport.GenerateGraph("Z:\\inetpub\\wwwroot\\proimages\\" + report.Selectedname + "-" + report.ReportName + DateTime.Now.ToString("ddMMyy") + repid.ToString() + "-" + report.ID + ".png", tables.Tables[0], graph, report.ReportName, report.Selectedname + "-" + report.ReportName + DateTime.Now.ToString("ddMMyy") + repid.ToString() + "-" + report.ID + ".png", report.GraphType); iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance("Z:\\inetpub\\wwwroot\\proimages\\" + report.Selectedname + "-" + report.ReportName + DateTime.Now.ToString("ddMMyy") + repid.ToString() + "-" + report.ID + ".png"); // scaling into the size jpg.ScaleToFit(450f, 350f); // spacing before image jpg.SpacingBefore = 50f; //spacing after image jpg.SpacingAfter = 1f; // aligning it ot centre jpg.Alignment = Element.ALIGN_CENTER; // Add to the PDF file pdfDoc.Add(jpg); } } } else { switch (report.ReportingSection) { case "Dashboar": Dashboard.GeneratePDFDashboardData(tables, report, pdfDoc); break; case "Invoice": string costcentrename = tables.Tables[1].Rows[0][0].ToString(); string fullname = costcentrename.Split(':')[0] + ":" + report.ListofFilters.Split('=', ',')[9].TrimStart('\'').TrimEnd('\''); List <string> names = new System.Collections.Generic.List <string>(); names.Add(fullname); names.Add("Cost Centre:"); names.Add("Overall:"); names.Add("Destination:"); pdfDoc.Open(); Invoice.GerateUCDpdfInvoiceHeader(pdfDoc, tables, report); int i = 0; foreach (DataTable dt in tables.Tables) { List <string> column = new List <string>(); foreach (DataColumn dc in dt.Columns) { column.Add(dc.ColumnName); } pdfDoc.Add(new iTextSharp.text.Paragraph(names[i], new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK))); pdfDoc.Add(new iTextSharp.text.Paragraph(" ")); PDFReports.BindPDFdata(pdfDoc, dt, column, Listoftotals(report.Totals)); pdfDoc.Add(new iTextSharp.text.Paragraph(" ")); i++; } pdfDoc.Close(); break; } } SendEmail.InsertPortfoliodetails(file, report.EmailAddresses, report.Portfolioreportid, report.ID); } catch { ReportStatus(report.ID, "ERROR"); } finally { pdfDoc.Close(); } } else { ReportStatus(report.ID, "No Data"); } }