Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
314
export chart and grid to pdf
posted

Hi,

I have a page that generates a chart and grid. I am trying to export the 2 controls to the same pdf file. I tryed to build on the illustration in:

http://help.infragistics.com/Help/NetAdvantage/NET/2007.3/CLR2.0/html/Chart_Exporting_Numerous_Charts_to_a_PDF.html

I added a grid to the page but it is not showing.

I removed the chart from the code the kept the grid then it showed.

I feel that a small thing is missing but I am lost. Any ideas? 

Parents
  • 314
    Verified Answer
    posted

     I managed to do it using 'bands'. If any one is interested in the code, here it is (the grid is filled from a datatable, I didn't use the grid exporter):

     

            Dim dt As datatable = Infragistics.UltraChart.Data.DemoTable.Table(4)
            Me.UltraWebGrid1.DataSource = dt
            Me.UltraWebGrid1.DataBind()      
          
            Dim numColumns As Integer = dt.Columns.Count
            Dim numRows As Integer = dt.Rows.Count

            Dim reportPath As String = _
                       System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
            Dim report As New Report()

            Dim section1 As Infragistics.Documents.Report.Section.ISection = report.AddSection

            'Dim page As Section.ISectionPage = section1.AddPage
            section1.PagePaddings = New Infragistics.Documents.Report.Paddings(50)

            '------Section Header-----------------------
            Dim sectionHeader As Infragistics.Documents.Report.Section.ISectionHeader = section1.AddHeader()
            sectionHeader.Repeat = True
            sectionHeader.Height = 50

            Dim sectionHeaderText As Infragistics.Documents.Report.Text.IText = sectionHeader.AddText(0, 0)
            sectionHeaderText.Paddings.All = 10
            sectionHeaderText.Alignment = _
              New TextAlignment(Alignment.Left, Alignment.Middle)
            sectionHeaderText.Height = New RelativeHeight(100)
            sectionHeaderText.AddContent("Sample")

            '-------------------------
            '----page numbering-------------
            Dim pn As Infragistics.Documents.Report.Section.PageNumbering = section1.PageNumbering
            pn.Style = New Infragistics.Documents.Report.Text.Style(Fonts.Arial, Infragistics.Documents.Graphics.Brushes.Black)
            pn.Template = "Page [Page #] of [TotalPages]"
            pn.SkipFirst = False
            pn.Alignment.Horizontal = Infragistics.Documents.Report.Alignment.Right
            pn.Alignment.Vertical = Infragistics.Documents.Report.Alignment.Bottom
            pn.OffsetY = -18
            '---------------

            Dim band1 As Infragistics.Documents.Report.Band.IBand = section1.AddBand
            Dim band2 As Infragistics.Documents.Report.Band.IBand = section1.AddBand

            band1.Paddings = New Infragistics.Documents.Report.Paddings(50)
            '--------------band1----------------
            Dim canvas As ICanvas = band1.AddCanvas
            canvas.Width = New FixedWidth(400)
            canvas.Height = New FixedHeight(300)
            Dim g As System.Drawing.Graphics = canvas.CreateGraphics()

            UltraChart1.ChartType = ChartType.GanttChart
            UltraChart1.Data.SwapRowsAndColumns = False
            UltraChart1.Data.DataSource = dt
            UltraChart1.Data.DataBind()
            UltraChart1.RenderPdfFriendlyGraphics(g)
            '-----------end band1---------------

            '---------------band2'--------------
            Dim gridPattern As New Infragistics.Documents.Report.Grid.GridPattern()

            gridPattern.Borders = New Borders(New Infragistics.Documents.Graphics.Pen(New Infragistics.Documents.Graphics.Color(0, 0, 0)), 5)
            gridPattern.Background = New Background(Infragistics.Documents.Graphics.Brushes.White)

            ' Create a new pattern for each cell.
            Dim cellPattern As New Infragistics.Documents.Report.Grid.GridCellPattern()
            cellPattern.Paddings = New Paddings(5, 10)
            cellPattern.Borders = New Borders(New Infragistics.Documents.Graphics.Pen(New Infragistics.Documents.Graphics.Color(0, 0, 0)))
            'cellPattern.Background = new Background(brush3);
            cellPattern.Alignment = _
              New Infragistics.Documents.Report.ContentAlignment(Alignment.Center, Alignment.Middle)

            Dim grid As Infragistics.Documents.Report.Grid.IGrid = band2.AddGrid
            grid.ApplyPattern(gridPattern)

            ' Declare a Column, Row, and Cell object
            ' for object creation.
            Dim gridColumn As Infragistics.Documents.Report.Grid.IGridColumn
            Dim gridRow As Infragistics.Documents.Report.Grid.IGridRow
            Dim gridCell As Infragistics.Documents.Report.Grid.IGridCell

            ' Add columns to the grid.
            For i As Integer = 0 To numColumns - 1
                gridColumn = grid.AddColumn()
            Next i

            ' Add a header to the grid.
            Dim gridHeader As Infragistics.Documents.Report.Grid.IGridHeader = grid.Header
            Dim headerCell As Infragistics.Documents.Report.Grid.IGridCell
            Dim headerCellText As Infragistics.Documents.Report.Text.IText
            For Each dc As DataColumn In dt.Columns
                headerCell = gridHeader.AddCell
                cellPattern.Apply(headerCell)
                headerCell.Background = New Background(Infragistics.Documents.Graphics.Brushes.LightSlateGray)
                headerCellText = headerCell.AddText
                headerCellText.Alignment = New TextAlignment(Alignment.Center, Alignment.Middle)
                headerCellText.AddContent(dc.ColumnName)
            Next

            ' Add a footer to the grid.
            Dim gridFooter As Infragistics.Documents.Report.Grid.IGridFooter = grid.Footer
            Dim footerCell As Infragistics.Documents.Report.Grid.IGridCell = _
              gridFooter.AddCell()
            footerCell.ColSpan = numColumns
            cellPattern.Apply(footerCell)
            Dim gridFooterText As Infragistics.Documents.Report.Text.IText = _
              footerCell.AddText()
            gridFooterText.Alignment = _
              New TextAlignment(Alignment.Right, Alignment.Middle)
            gridFooterText.AddContent("Grid Footer")


            'Add rows to the grid

            For Each dr As DataRow In dt.Rows
                gridRow = grid.AddRow()
                For i As Integer = 0 To numColumns - 1
                    gridCell = gridRow.AddCell()
                    cellPattern.Apply(gridCell)
                    gridCell.AddQuickText(dr(i).ToString)
                Next
            Next
            '----------------end band2------------------

            report.Publish(reportPath + "\Report.pdf", FileFormat.PDF)

     

Reply Children
No Data