GridView Export To PDF

2 posts, 0 answers
  1. Cyril
    Cyril avatar
    10 posts
    Member since:
    Sep 2014

    Posted 08 Jun 2017 Link to this post

    Hello,

    How Draw into cell of gridview ???

    Thanks for you help

    My sample of code below :

    Dim oRadGridView as RadGridView = new RadGridView()

    Dim oPDFExporter As New GridViewPdfExport(oRadGridView)
    With oPDFExporter
       AddHandler .CellFormatting, AddressOf oPDFExporter_CellFormatting
       AddHandler .CellPaint, AddressOf oPDFExporter_CellPaint
       .PageMargins = New Padding(10, 10, 10, 10)
       .ExportSettings = oPdfExportSettings
       If bLandScape Then
         .PageSize = New SizeF(297, 210)
       Else
         .PageSize = New SizeF(210, 297)
       End If
      .ShowHeaderAndFooter = True
      .FileExtension = ".pdf"
      .HiddenColumnOption = HiddenOption.DoNotExport
      .ShowHeaderAndFooter = True
      .HeaderHeight = iHeightHeader
      .HeaderFont = New System.Drawing.Font("Arial", 8, FontStyle.Regular)
      .LeftHeader = sLeftHeader
      .MiddleHeader = sMiddleHeader
      .RightHeader = sRightHeader
      .ReverseHeaderOnEvenPages = True
      .FooterHeight = 30
      .FooterFont = New System.Drawing.Font("Arial", 8, FontStyle.Regular)
      .SummariesExportOption = SummariesOption.ExportAll
      .ExportGroupedColumns = True
      .ExportHeaderRowOnEachPage = True
      '.FitToPageWidth = True
      Using oMemoryStream As New MemoryStream()
         Dim oRenderer As New PdfExportRenderer
         .RunExport(oMemoryStream, oRenderer)
         Using oFileStream As New FileStream(sPDFDocumentName, FileMode.Create, FileAccess.Write)
           oMemoryStream.WriteTo(oFileStream)
         End Using
         oRenderer = Nothing
       End Using
    End With
    oPdfExportSettings = Nothing
    oPDFExporter = Nothing

    Private Sub oPDFExporter_CellFormatting(sender As Object, e As PdfExportCellFormattingEventArgs)

    End Sub

    Private Sub oPDFExporter_CellPaint(sender As Object, e As ExportCellPaintEventArgs)
                Dim oPDFExporter As GridViewPdfExport = DirectCast(sender, GridViewPdfExport)
                Dim oRadGridView As RadGridView = oPDFExporter.RadGridViewToExport
                With e
                    .Cell.TextWrap = True
                    Dim oSize As SizeF = .Rectangle.Size
                    Dim iX As Integer = .Rectangle.X + (oSize.Width - 20)
                    Dim iY As Integer = .Rectangle.Y
                    Select Case .Cell.ColumnIndex
                        Case "column_category"
                            If oRadGridView.Rows(e.Cell.RowIndex).Cells(13).Value = True Then
    'HOW DRAW INTO CELL ?????
                                '.Cell.Graphics.DrawString("€", New System.Drawing.Font("Segoe UI", 11), Brushes.Blue, New PointF(iX, iY))
                            End If
                    End Select
                    oSize = Nothing
                End With
                oRadGridView = Nothing
                oPDFExporter = Nothing
    End Sub

  2. Dimitar
    Admin
    Dimitar avatar
    2834 posts

    Posted 08 Jun 2017 Link to this post

    Hello Cyril,

    You can use the following code to draw a string:
    Dim editor = TryCast(e.Editor, PdfEditor)
    editor.SetFillColor(Color.Red)
    editor.DrawText("Test")

    Detailed information about the editor is available here: FixedContentEditor.

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top