Asked by:
itextsharp to convert persian gridview to pdf not working

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
-
User1508394307 posted
So does it output non-arabic grid or any non-arabic text without grid?
Tuesday, November 18, 2014 1:41 PM -
User1897897189 posted
yes,,, english characters are ok..but not arabic...
Tuesday, November 18, 2014 1:49 PM -
User1508394307 posted
Try other fonts as suggested
http://stackoverflow.com/questions/15197040/arabic-encoding-in-itextsharp/15201049#15201049
http://stackoverflow.com/questions/6130470/hebrew-text-in-pdf/6130733#6130733Tuesday, November 18, 2014 1:59 PM -
User1897897189 posted
i tried above links..
still its the same..
i have a grid view and it has arabic data, i just wanted to export to pdf.. thats it,english is coming good but not arabic...pls help me...
could you please let me know from where i can download the latest version of itextsharp?
thanks
nick
Tuesday, November 18, 2014 2:04 PM -
User1897897189 posted
i got the above code from the following link
its giving me an error in following line
cell.BackgroundColor = New Color(GridView1.HeaderStyle.BackColor)
it says 'System.drawing.colour' has no constructors. but when i change to basecolor like below its passing the exception
but its giving me nothing as op
cell.BackgroundColor = New baseColor(GridView1.HeaderStyle.BackColor)
Tuesday, November 18, 2014 2:15 PM