0

I have coded java code and I wanted Arabic words to be displayed at PdfPTable which was asses to itext document to create PDF document

as attached picture "???" is Arabic code '

PdfPTable header = new PdfPTable(6);
PdfPTable tbame = new PdfPTable(1);
tbame.addCell("                                 >>>>>>     " + install.getCustId().getFullName() + "    <<<<<<");
tbame.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
tbame.setLockedWidth(false);
tbame.setExtendLastRow(false);
tbame.setWidthPercentage(100);
header.addCell("End");
header.addCell("Start");
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165

1 Answers1

1

Please read the documentation and you'll find out that the addCell(String content) method can not be used to add Arabic text for two reasons:

  1. When you use this method, the default font Helvetica is used. You need to use a font that knows how to draw Arabic shapes. This is explained in the answer to this question: Itext Arabic Font coming as question marks
  2. Arabic is written from right to left, which means that you need to change the run direction of the content of the cell as is explained in my answer to this question: RTL not working in pdf generation with itext 5.5 for Arabic text

A code snippet:

BaseFont bf  = BaseFont.createFont("c:/WINDOWS/Fonts/arialuni.ttf",
    BaseFont.IDENTITY_H, BaseFont.EMBEDDED); 
Font font = new Font(bf, 12);
Phrase phrase = new Phrase(
    "\u0644\u0648\u0631\u0627\u0646\u0633 \u0627\u0644\u0639\u0631\u0628", font);
PdfPCell cell = new PdfPCell(phrase);  
cell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
table.addCell(cell);

If you don't have access to the font arialuni.ttf, you'll have to find another font that contains Arabic glyphs.

Community
  • 1
  • 1
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165