如何在使用itext 7 API生成的PDF中显示RTL的阿拉伯字符串?

我现在几个小时都在努力解决这个问题,但我找不到出路,问题是:

我编写了一个程序,使用itext版本7(以及很多版本)生成一个pdf文件以及一些统计信息,每个事情都是正确的,但是当我的pdf应该包含一些阿拉伯字符串时,它们只是从左到右出现,没有重要的是我尝试过(更改字体,使用通用编码,将字符串放在表格的单元格内,使用canvas,……)我无法使它们正常显示。 这是我用来显示阿拉伯字符串的一段代码:

PdfFont fArabic=PdfFontFactory.createFont(ARABICFONT,PdfEncodings.IDENTITY_H, true); final String ARABIC = "\u0627\u0644\u0633\u0644\u0627\u0645 \u0639\u0644\u064A\u0643\u0645"; document.add(new Paragraph(ARABIC).setFont(fArabic).setBaseDirection(BaseDirection.RIGHT_TO_LEFT)); 

注意:我认为itext 5版本也许可以解决它,但正如我所说,我无法撤消我编写的代码,特别是我有它的第三个统计库,而且项目已经很晚了。我只想要一个使用itext的解决方案7版。

第1步:将pdfCalligraph和licensekey jar加载到类路径中

第2步:从xml文件加载许可证密钥:

 LicenseKey.loadLicenseFile("itextkey-typography.xml"); 

第3步:照常创建Document

 Document document = new Document(new PdfDocument(new PdfWriter(outFileName))); PdfFont bf = PdfFontFactory.createFont(ARABIC_FONT, PdfEncodings.IDENTITY_H); document.setFont(bf); document.add(new Paragraph(ARABIC_TEXT).setTextAlignment(TextAlignment.RIGHT)); document.close();