Different problems may be at play.
- Encoding: You are putting Arabic text in your source code. If you save your Java file using the wrong encoding, that text will become corrupt. If you compile your Java file using the wrong encoding, that text will become corrupt. And so on. I hope you get the idea. Store literal text like this:
"\u0644\u0648\u0631\u0627\u0646\u0633 \u0627\u0644\u0639\u0631\u0628"
to avoid problems like this. - As documented in Chapter 11 of my book, right-to-left writing and Arabic ligatures are only supported in the context of
PdfPCell
andColumnText
. I see that you're usingPdfPCell
, but I don't see you usingcell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
anywhere. That's wrong. - You are using an object
fontNormal
, but you're not telling us which font you're actually using. For instance: if you're using the standard Type1 font Helvetica, no text will show up, because Helvetica doesn't know how to render Arabic text.
Amendment: You've now updated your question, showing that you're using "arialuni.ttf"
. However, you are using the wrong encoding: CP1252 is the encoding for the Latin Alphabet. You should use BaseFont.IDENTITY_H
.
Update: looking at the update of your question as well as the extra comment, I see two major errors.
- You are assuming that the name of the font is
"arialuni.ttf"
. That's the font file, but not the font name. Also: you are asking theFontFactory
for this font, but did you tell theFontFactory
where to look for fonts? Are you sure theFontFactory
can locatec:/windows/fonts/
or whatever directory the filearialuni.ttf
is stored. - You are declaring a font, but you're not using it:
Paragraph p = new Paragraph("\u062D\u064A\u0633\u0648");
creates aParagraph
using the default font.
This is code that works:
BaseFont bf = BaseFont.createFont(
"c://windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font font = new Font(bf, 8);
PdfPTable table = new PdfPTable(1);
PdfPCell cell = new PdfPCell(new Phrase("\u062D\u064A\u0633\u0648", font));
cell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
table.addCell(cell);
document.add(table);
The result looks like this (zoomed in):