locked
itextsharp to convert persian gridview to pdf not working RRS feed

  • Question

  • User1897897189 posted

    dear all,\\

    I WANT TO EXPORT gridview data to pdf.

    ii am using itextsharp. gridview data has persian/arabic data.

    i tried level best to make it work but its not giving me the expected op.

    its givig me nothing, just  a blank pdf file... what could be the reason ?

    following is my code

            GridView1.DataSource = Session("dt")
            GridView1.AllowPaging = False
            GridView1.DataBind()

            Dim bf As BaseFont = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") & "\fonts\tahoma.ttf", BaseFont.IDENTITY_H, True)
            Dim font As New iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL)
            Dim table As New iTextSharp.text.pdf.PdfPTable(GridView1.Columns.Count)
            Dim widths As Integer() = New Integer(GridView1.Columns.Count - 1) {}
            For x As Integer = 0 To GridView1.Columns.Count - 1
                widths(x) = CInt(GridView1.Columns(x).ItemStyle.Width.Value)
                Dim cellText As String = Server.HtmlDecode(GridView1.HeaderRow.Cells(x).Text)
                Dim cell As New iTextSharp.text.pdf.PdfPCell(New Phrase(12, cellText, font))
                cell.BackgroundColor = New BaseColor(GridView1.HeaderStyle.BackColor)
                'cell.BackgroundColor = New BaseColor(System.Drawing.ColorTranslator.FromHtml("#008000"))
                cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL
                table.AddCell(cell)
            Next
            table.SetWidths(widths)

            For i As Integer = 0 To GridView1.Rows.Count - 1
                If GridView1.Rows(i).RowType = DataControlRowType.DataRow Then
                    For j As Integer = 0 To GridView1.Columns.Count - 1
                        Dim cellText As String = Server.HtmlDecode(GridView1.Rows(i).Cells(j).Text)
                        Dim cell As New iTextSharp.text.pdf.PdfPCell(New Phrase(12, cellText, font))
                        'Set Color of Alternating row
                        If i Mod 2 <> 0 Then
                            'cell.BackgroundColor = New BaseColor(System.Drawing.ColorTranslator.FromHtml("#C2D69B"))
                            cell.BackgroundColor = New BaseColor(GridView1.RowStyle.BackColor)
                        End If
                        cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL
                        table.AddCell(cell)
                    Next
                End If
            Next

            'Create the PDF Document
            Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 0.0F)
            PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
            pdfDoc.Open()
            pdfDoc.Add(table)
            pdfDoc.Close()
            Response.ContentType = "application/pdf"
            Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf")
            Response.Cache.SetCacheability(HttpCacheability.NoCache)
            Response.Write(pdfDoc)
            Response.[End]()

    thanks\]

    nick

    Tuesday, November 18, 2014 1:12 PM

All replies