PDFBox 3.0.0 show complex non latin fonts

79 views Asked by At

I'm trying to print non-latin (Indian) text in a PDF. I'm using Lohit-Devanagari as PDType0Font but the resulting PDF puts each character as is instead of converting it to its respective complex character:

var sample="प्रदेश ग्रामीण व्यवसायिक";
try(var document=new PDDocument(){
    var hin=PDType0Font.load(document,
                             new File(Example.class().getResource("hindi.ttf").getFile())
    );
    var page=new PDPage(PDRectangle.A4);
    document.addPage(page);
    try(var stream=newPDPageContentStream(document,page)){
        var codes=hin.encode(sample);
        var strLine=new StringBuilder();
        for(var code:codes){
            if(code!=0){
                strLine.append(hin.toUnicode(code));
            }
        }
        stream.setFont(hin,10);
        stream.beginText();
        stream.newLineAtOffset(30,50);
        stream.showText(strLine.toString());
        stream.endText();
    }
    document.save("output.pdf");
}catch(IOException ex){
    System.out.println(ex);
}

The output is: output

PDF details:

Lohit-Devanagari (Embedded subset)
Type: TrueType (CID)
Encoding: Identity-H
0

There are 0 answers