0

I'm using Visual Basic Express 2010 and I exported my data from DataGridView to PDF using iTextSharp, the data contains both English and Arabic Language. the English data exported successfully but the Arabic does not exported.

which code should I use to export the Arabic data?

here is my code...

Imports iTextSharp.text
Imports iTextSharp.text.pdf 

'AND
'==================================================

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim pdfTable As New PdfPTable(DataGridView1.ColumnCount)
        pdfTable.DefaultCell.Padding = 3
        pdfTable.WidthPercentage = 30
        pdfTable.HorizontalAlignment = Element.ALIGN_LEFT
        pdfTable.DefaultCell.BorderWidth = 1
        'Adding Header row
        For Each column As DataGridViewColumn In DataGridView1.Columns
            Dim cell As New PdfPCell(New Phrase(column.HeaderText))
            'cell.BackgroundColor = New iTextSharp.text.Color(240, 240, 240)
            pdfTable.AddCell(cell)
        Next
        'Adding DataRow
        For Each row As DataGridViewRow In DataGridView1.Rows
            For Each cell As DataGridViewCell In row.Cells
                If cell.Value IsNot Nothing AndAlso cell.Value.ToString <> "" Then
                    pdfTable.AddCell(cell.Value.ToString())
                Else
                    pdfTable.AddCell("")
                End If
            Next
        Next
        'Exporting to PDF
        Dim folderPath As String = "C:\Users\sh\Desktop\FP\"
        If Not Directory.Exists(folderPath) Then
            Directory.CreateDirectory(folderPath)
        End If
        Using stream As New FileStream(folderPath & "DataGridViewExport.pdf", FileMode.Create)
            Dim pdfDoc As New Document(PageSize.A2, 10.0F, 10.0F, 10.0F, 0.0F)
            PdfWriter.GetInstance(pdfDoc, stream)
            pdfDoc.Open()
            pdfDoc.Add(pdfTable)
            pdfDoc.Close()
            stream.Close()
        End Using
    End Sub 
Daniel Dušek
  • 13,683
  • 5
  • 36
  • 51
Fatimah246
  • 27
  • 3
  • 1
    Use a font that knows how to render Arabic glyphs. – Bruno Lowagie Dec 27 '16 at 10:50
  • 1
    As you can see in the answer to the duplicate question, you need to make sure that you use a font that contains Arabic glyphs. You are using the default font (Helvetica) and that font can't write Arabic. Furthermore, you have to change the run direction of the `PdfPCell` because otherwise your glyphs will be written from left to right instead of from right to left, and no ligatures will be made. The answer to the duplicate question is in Java, but the same principles apply to VB. Note that many of these problems were solved in iText 7 with the pdfCalligraph add-on. – Bruno Lowagie Dec 27 '16 at 10:54
  • Bruno Lowagie - would you please write the code – Fatimah246 Dec 27 '16 at 13:14
  • Please don't ask me to write VB code. The last time I wrote VB code was in 1996. You have the Java code. It shouldn't be a problem to port that to VB code. – Bruno Lowagie Dec 27 '16 at 13:44
  • i used Arial font and the arabic word is showing in pdf BUT IN INVERSE LETTER. but i tried this in an example to showing a word in pdf. now i want to view a DataGridView with arabic letter – Fatimah246 Dec 29 '16 at 16:15
  • and another Q how can i convert C# to VB.net. i found many examples but in C# not in VB.net – Fatimah246 Dec 29 '16 at 16:16
  • OF COURSE THE TEXT IS RENDERED IN THE WRONG DIRECTION! Didn't you read my comment **Furthermore, you have to change the run direction of the PdfPCell because otherwise your glyphs will be written from left to right instead of from right to left, and no ligatures will be made.** If you're a serious VB developer, read the C# as if it were pseudocode. No examples in VB.net will be provided because VB.net usually isn't used in a professional context. – Bruno Lowagie Dec 29 '16 at 16:19
  • sorry, i read it but i thought when you wrote **left to right** you mean the place in the screen. – Fatimah246 Dec 29 '16 at 19:36
  • it's the first time i write a vb code, i didn't even study it in college. – Fatimah246 Dec 29 '16 at 19:36
  • big thanks for you help, i will try and it will works in shaa allah – Fatimah246 Dec 29 '16 at 19:37

0 Answers0