androidpdfitextarabicpersian

Itext show empty line for Arabic words


I am using Itext to create pdf files in android using below code:

 Document document = new Document();
                PdfWriter.getInstance(document, new FileOutputStream(root.getPath() + "/" + System.currentTimeMillis() + ".pdf"));
                document.open();
                Font chapterFont = FontFactory.getFont("", BaseFont.IDENTITY_H, 16, Font.BOLDITALIC);
                Font paragraphFont = FontFactory.getFont("", BaseFont.IDENTITY_H, 12, Font.NORMAL);

                Chunk chunk = new Chunk(b.getTitle(), chapterFont);

                Chapter chapter = new Chapter(new Paragraph(chunk), 1);
                chapter.setNumberDepth(0);
                chapter.add(new Paragraph(b.getLead(), paragraphFont));
                document.add(chapter);
                document.close();

when i use english words it works fine, but when i use arabic or persian words it shows empty lines,

what is the problem? and how can i solve it? thanks in advance,


Solution

  • This problem fixed by changing this line:

    Font chapterFont = FontFactory.getFont("", BaseFont.IDENTITY_H, 16, Font.BOLDITALIC);
    

    to

    Font chapterFont = FontFactory.getFont("assets/arial.ttf", BaseFont.IDENTITY_H, 16, Font.BOLDITALIC);