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?