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);
}
PDF details:
Lohit-Devanagari (Embedded subset)
Type: TrueType (CID)
Encoding: Identity-H