Pdf generation using itext for Bangla text in android

Viewed 806

I am using i-text for generating pdf from my android application. But it worked fine for English fonts. When I was trying to generate pdf for my locale, Bangla, I got some problems. After getting some tips from some blog I have got the implementation in the way mentioned bellow:

String fontName = "Nikosh.ttf";
    InputStream is = context.getAssets().open(fontName);
    int size = is.available();
    byte[] buffer = new byte[size];
    int a = is.read(buffer);
    BaseFont customFont = BaseFont.createFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, true, buffer, buffer);
    Font banglaFont = new Font(customFont, 12);

Now the output looks like this:

This is the output for Bangla text using a bangla font

image

But the output text is broken. Whereas the original one looks like this one:

Original text in Bangla

image2

Any help regarding how to solve this type of problem for unicode in android would be highly appreciated. N.B. I am using i-text 5.5.x

2 Answers

Use font that display as well.

BaseFont base = BaseFont.createFont("c:/windows/fonts/arial.ttf", BaseFont.WINANSI);
Font font = new Font(base, 11f, Font.BOLD);

Use this library :

implementation 'com.uttampanchasara.pdfgenerator:pdfgenerator:1.3' 

minsdk :

above 21
Related