private Infragistics.Documents.Reports.Report.Section.ISection formatPage(Infragistics.Documents.Reports.Report.Section.ISection s1) { //sets properties on the section //to add page numbers s1.PageNumbering.SkipFirst = true; s1.PageNumbering.OffsetY = -18; s1.PageNumbering.Template = "Page [Page #] of [TotalPages]"; //adds a header to the PDF Infragistics.Documents.Reports.Report.Section.ISectionHeader s1header = s1.AddHeader(); s1header.Height = 20; s1header.Repeat = false; //adds text to the header area Infragistics.Documents.Reports.Report.Text.IText s1headertitle = s1header.AddText(0, 0); s1headertitle.AddContent("Logic University :" + drdReportList.SelectedItem.ToString()); s1headertitle.Alignment = TextAlignment.Left; Infragistics.Documents.Reports.Report.Text.IText s1headertimestamp = s1header.AddText(0, 0); s1headertimestamp.AddContent("Generated on: "); s1headertimestamp.AddDateTime("MM/dd/yyyy hh:mm:ss"); s1headertimestamp.Alignment = TextAlignment.Right; return(s1); }
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>"); } }