ITextPdf: print Arabic lines from right to left (RTL)

I use iTextpdf in Java to create stamped PDF files, sometimes the generated PDF file in Arabic, and I am facing a funny problem. To allow the creation of an Arab page from right to left (RTL), I use tables and cells that have a property PdfPCell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL). When I use this property, the Arabic language is not displayed at all, if I avoid accessing this property, the Arabic lines are displayed correctly, this means that I should not have problems with fonts, and I really do not know if this is a problem with iText or I just missed something.

Here is a small piece of code that correctly displays the Arabic line:

BaseFont bf = BaseFont.createFont(Application.getBASEPATH() + "fonts/arabic.ttf",BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font trebuchetSmaller = new Font(bf, 10, 0);

PdfPTable tbl = new PdfPTable(1); 
PdfPCell cell = new PdfPCell();
Paragraph paragraph = new Paragraph();
paragraph.add(new Phrase("ربط صفحة على شبكة الإنترنت"), trebuchetSmaller));
cell.addElement(paragraph);
tbl.addCell(cell);

Here is the necessary change that makes the arabic string disappear:

BaseFont bf = BaseFont.createFont(Application.getBASEPATH() + "fonts/arabic.ttf",BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font trebuchetSmaller = new Font(bf, 10, 0);

PdfPTable tbl = new PdfPTable(1); 
PdfPCell cell = new PdfPCell();
cell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
Paragraph paragraph = new Paragraph();
paragraph.add(new Phrase("ربط صفحة على شبكة الإنترنت"), trebuchetSmaller));
cell.addElement(paragraph);
tbl.addCell(cell);

PdfWriter.RUN_DIRECTION_RTL , , . , .

+3
2

, :

new Phrase("آزمايش", font)

:

PdfPCell pdfCell = new PdfPCell(new Phrase("آزمايش", font));  
pdfCell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL); 
+3
+1

All Articles