如何使用iTextSharp将带有ARABIC数据的DataGridView从Visual Basic导出为PDF

时间:2016-12-27 08:45:21

标签: vb.net visual-studio pdf itext

我正在使用 Visual Basic Express 2010 我使用iTextSharp 将数据从DataGridView 导出到PDF,数据包含英语和阿拉伯语。 英语数据成功导出但阿拉伯语未导出。

我应该使用哪些代码导出阿拉伯数据?

这是我的代码......

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 

0 个答案:

没有答案