On using iText 8 with pdfCalligraph add-on, the Arabic characters are separated, which is incorrect.
Output:
Expected:
هذه هي الجملة المستخدمة في المثال
- com.itextpdf:iText 8.0.5
- com.itextpdf:typography 4.0.2
- Font file was downloaded from here
A minimized sample take from the website, also including the hints in the video:
Update: For some reason, changing the font to the one inside the typography.jar (NotoSansArabic-Regular.ttf
) seems to work, but I am not sure why Naskh
font doesn’t work.
class Abc {
public static void main(String[] args) throws IOException {
LicenseKey.loadLicenseFile(new File("path to license.json"));
try (var writer = new PdfWriter("out.pdf");
var pdfDocument = new PdfDocument(writer);
var document = new Document(pdfDocument)) {
var font_path = Thread.currentThread().getContextClassLoader().getResource(
"NotoNaskhArabic-Regular.ttf");
PdfFontFactory.register(font_path.toString());
System.out.println(PdfFontFactory.getRegisteredFonts());
var font = PdfFontFactory.createRegisteredFont("noto naskh arabic", PdfEncodings.IDENTITY_H);
var paragraph = new Paragraph()
.setFont(font)
.setBaseDirection(BaseDirection.RIGHT_TO_LEFT)
.setTextAlignment(TextAlignment.RIGHT);
paragraph.add("هذه هي الجملة المستخدمة في المثال");
document.add(paragraph);
}
}
}