1

As per instructions here, I've tried but could not find a similar question / issue.

On Ubuntu, using:

iText Core 7.2.1
pdfCalligraph 3.0.0

This code:

Document doc = new Document(new PdfDocument(new PdfWriter(new ByteArrayOutputStream())));
PdfFont urduFont = PdfFontFactory.createFont("Jameel_Noori_Nastaliq.ttf", PdfEncodings.IDENTITY_H, EmbeddingStrategy.FORCE_EMBEDDED);

String hope = "\u0627\u064f\u0645\u0651\u06cc\u062f"; // اُمّید
Text text = new Text(hope).setFont(urduFont).setTextAlignment(TextAlignment.RIGHT);

doc.add(new Paragraph(text).setBaseDirection(BaseDirection.RIGHT_TO_LEFT).setFontScript(UnicodeScript.ARABIC));

Throws:

java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
    at com.itextpdf.layout.renderer.LineRenderer.updateBidiLevels(LineRenderer.java:1496)
    at com.itextpdf.layout.renderer.LineRenderer.layout(LineRenderer.java:178)
    at com.itextpdf.layout.renderer.ParagraphRenderer.directLayout(ParagraphRenderer.java:234)
    at com.itextpdf.layout.renderer.ParagraphRenderer.layout(ParagraphRenderer.java:106)
    at com.itextpdf.layout.renderer.RootRenderer.addChild(RootRenderer.java:141)
    at com.itextpdf.layout.RootElement.createAndAddRendererSubTree(RootElement.java:367)
    at com.itextpdf.layout.RootElement.addElement(RootElement.java:376)
    at com.itextpdf.layout.RootElement.add(RootElement.java:105)
    at com.itextpdf.layout.Document.add(Document.java:140)

Here is a list of words I tested with Jameel Noori Nastaliq - one of the most elegant Urdu fonts. Same results were observed (with a different set of words) when tested with Nafees Nastaliq, Noto Nastaliq and Amar Nastaliq fonts.


Secondly, some words (a few hundred at least; again varying with fonts) look jumbled up:

iText (bad):

vs. HTML (good):

Here is more exhaustive list of words tested with Jameel Noori Nastaliq.

\u0691 seems to be one of the most problematic characters. Others include some diacritics as well.

Is there a hope to fix this without trying and switching to other fonts?

Irfan Latif
  • 498
  • 2
  • 9
  • 24
  • Unfortunately this is a bug. I recommend that you contact iText Support / Sales team at https://itextpdf.com/contact depending on whether you are an existing customer or a prospect. – Alexey Subach Jan 25 '22 at 22:38
  • @AlexeySubach thank you for the response. I had reported the bug to the sales manager via email. The solution I ended up with was converting HTML to PDF using `wkhtmltopdf`, though it wasn't as flexible and convenient to work with as `iText` is. I'd like to work with `iText` in future. I hope the issues get fixed in the coming releases. – Irfan Latif Feb 13 '22 at 13:54

0 Answers0