pdf itextsharp中的阿拉伯语不起作用

问题描述 投票:0回答:1

我正在尝试使用阿拉伯语和英语的混合来创建pdf,但效果不明显。

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

vb.net pdf itext
1个回答
0
投票

如Paulo所说,

仅在ColumnTextPdfPTable内部起作用。

此外,您必须通过选择主要运行方向来激活对双向类型设置的支持。

您要求的简单示例

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()
© www.soinside.com 2019 - 2024. All rights reserved.