Muhammed RYHAN
Muhammed RYHAN

Reputation: 117

arabic languge in pdf itextsharp not working

i'm trying to create pdf using mix from Arabic and English but is not working clearly.

Dim Doc1 As Object = New Document()
Dim Path As String
Dim fontpath As String = "C:\Windows\Fonts"
Dim customfont As BaseFont = BaseFont.CreateFont(fontpath & "/Arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)
Dim Myfont As Font = New Font(customfont, 12)
Path = "C:\Users\LENOVO\Desktop\docs"
PdfWriter.GetInstance(Doc1, New FileStream(Path + "\Doc1.pdf", FileMode.Create))
Doc1.Open()
Doc1.Add(New Paragraph(" ملف جديد", Myfont))
Doc1.Close()

screen shot

Upvotes: 2

Views: 336

Answers (1)

mkl
mkl

Reputation: 95918

As Paulo already commented,

It will only work inside ColumnText or PdfPTable.

Furthermore, you will have to activate support for bidirectional type setting by selecting the primary run direction.

You asked for a simple example:

Dim Doc1 As Object = New Document()
Dim Path As String
Dim fontpath As String = "C:\Windows\Fonts"
Dim customfont As BaseFont = BaseFont.CreateFont(fontpath & "/Arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)
Dim Myfont As Font = New Font(customfont, 12)
Path = "C:\Temp\test-results\content"
PdfWriter.GetInstance(Doc1, New FileStream(Path + "\WriteArabicLikeRyhana-Improved.pdf", FileMode.Create))
Doc1.Open()
Dim table As PdfPTable = New PdfPTable(1)
table.WidthPercentage = 100
Dim cell As PdfPCell = New PdfPCell()
cell.Border = PdfPCell.NO_BORDER
cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL
cell.AddElement(New Paragraph(" ملف جديد", Myfont))
table.AddCell(cell)
Doc1.add(table)
Doc1.Close()

The result:

screen shot

Upvotes: 1

Related Questions