арабский c язык в pdf itextsharp не работает - PullRequest
1 голос
/ 30 января 2020

Я пытаюсь создать PDF, используя микс от Араби c и Энгли sh, но не работает четко.

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

1 Ответ

0 голосов
/ 30 января 2020

Как уже прокомментировал Пауло,

Он будет работать только внутри ColumnText или PdfPTable.

Кроме того, вам придется активировать поддержку двунаправленного типа. установка путем выбора основного направления движения.

Вы запросили простой пример :

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()

Результат:

screen shot

...