PDFBox unicode font issue - Bangla unicode font is broken in generated PDF using PDFbox in Java

706 Views Asked by At

I want to generate a PDF that contains Bangla text. After generating PDF, text in generated PDF is broken. I have gone through a lot of Q/A related to this problem in StackOverflow, but unfortunately, I didn't find any suitable answer. here is my code...

try (PDDocument doc = new PDDocument()) {
    PDPage pdPage = new PDPage(PDRectangle.A4);
    doc.addPage(pdPage);

    PDPageContentStream cs = new PDPageContentStream(doc, pdPage);

    InputStream fontFileStream = new FileInputStream("src/main/resources/SolaimanLipi_22-02-2012.ttf");

    PDFont banglaFont = PDType0Font.load(doc, fontFileStream, false);

    cs.beginText();
    cs.setFont(banglaFont, FONT_SIZE);
    cs.newLineAtOffset(30, 500);
    cs.showText("অভিনন্দন! প্রিয়  আবিদ হাসান,");
    cs.endText();
    cs.close();
    doc.save(location);

} catch (IOException e) {
    log.error("PDF Error : {}", e.getMessage(), e);
}

My expected output in generated PDF.

enter image description here

But What I got in generated PDF (Broken).

enter image description here

Can anyone please help me to sort out this problem???

0

There are 0 best solutions below