protected void PDFDownload_Click(object sender, ImageClickEventArgs e) { string fileName = HttpUtility.UrlEncode(drdReportList.SelectedItem.Text.Trim() + System.DateTime.Now.ToString()); fileName = fileName.Replace("+", "_"); if (WebTab1.SelectedIndex == 0) { dgvReport.DataSource = (DataTable)Session["ReportData"]; dgvReport.DataBind(); //creates a report object Infragistics.Documents.Reports.Report.Report r = new Infragistics.Documents.Reports.Report.Report(); //adds a section to add content to Infragistics.Documents.Reports.Report.Section.ISection s1 = r.AddSection(); formatPage(s1); this.PDFExporter.DownloadName = fileName; this.PDFExporter.Format = Infragistics.Web.UI.GridControls.FileFormat.PDF; this.PDFExporter.DataExportMode = Infragistics.Web.UI.GridControls.DataExportMode.AllDataInDataSource; this.PDFExporter.TargetPaperOrientation = PageOrientation.Portrait; this.PDFExporter.Margins = PageMargins.Normal; this.PDFExporter.TargetPaperSize = PageSizes.A4; this.PDFExporter.Export(dgvReport, r, s1); } else { if (rdBarChart.Checked) { chartReport.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.BarChart; } else if (rdlineChart.Checked) { chartReport.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.StackSplineAreaChart; } else if (pointChart.Checked) { chartReport.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.StackLineChart; } chartReport.DataSource = (DataTable)Session["chartData"]; chartReport.DataBind(); //creates a report object Infragistics.Documents.Reports.Report.Report r = new Infragistics.Documents.Reports.Report.Report(); //adds a section to add content to Infragistics.Documents.Reports.Report.Section.ISection s1 = r.AddSection(); s1 = formatPage(s1); this.chartReport.RenderPdfFriendlyGraphics(r.AddSection().AddCanvas().CreateGraphics(), 500, 300); r.Publish(@"d:\" + fileName + ".pdf", FileFormat.PDF); Session["pdfFileName"] = @"d:\" + fileName + ".pdf"; Page.ClientScript.RegisterStartupScript(this.GetType(), "Myscript", "<script language='javascript'> " + "window.open('../commonUI/PrintReport.aspx?pdf=yes&excel=no');</script>"); } }
protected void PrintButton_Click(object sender, ImageClickEventArgs e) { string fileName = HttpUtility.UrlEncode(drdReportList.SelectedItem.Text.Trim() + System.DateTime.Now.ToString()); fileName = fileName.Replace("+", "_"); if (WebTab1.SelectedIndex == 1) { if (rdBarChart.Checked) chartReport.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.BarChart; else if (rdlineChart.Checked) chartReport.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.StackSplineAreaChart; else if (pointChart.Checked) chartReport.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.StackLineChart; chartReport.DataSource = (DataTable)Session["chartData"]; chartReport.DataBind(); //creates a report object Infragistics.Documents.Reports.Report.Report r = new Infragistics.Documents.Reports.Report.Report(); //adds a section to add content to Infragistics.Documents.Reports.Report.Section.ISection s1 = r.AddSection(); s1 = formatPage(s1); this.chartReport.RenderPdfFriendlyGraphics(r.AddSection().AddCanvas().CreateGraphics(), 500, 300); r.Publish(@"d:\" + fileName + ".pdf", FileFormat.PDF); //Response.Clear(); Session["pdfFileName"] = @"d:\" + fileName + ".pdf"; Page.ClientScript.RegisterStartupScript(this.GetType(), "Myscript", "<script language='javascript'> " + "window.open('../commonUI/PrintReport.aspx?pdf=yes&excel=no');</script>"); } else { dgvReport.DataSource = (DataTable)Session["ReportData"]; dgvReport.DataBind(); this.PDFExporter.DownloadName = fileName; this.PDFExporter.Format = Infragistics.Web.UI.GridControls.FileFormat.PDF; this.PDFExporter.DataExportMode = Infragistics.Web.UI.GridControls.DataExportMode.AllDataInDataSource; this.PDFExporter.TargetPaperOrientation = PageOrientation.Portrait; this.PDFExporter.Margins = PageMargins.Normal; this.PDFExporter.TargetPaperSize = PageSizes.A4; this.PDFExporter.Export(dgvReport); } }