Search code examples
javapdfitextarabic

Some Arabic Letters are Missing in my PDF


I have the following test code

Font arabic = FontFactory.getFont("C:\\Windows\\Fonts\\simpo.ttf",BaseFont.IDENTITY_H,16);

     try {
         Document d=new Document();
         PdfWriter writer = PdfWriter.getInstance(d, new FileOutputStream("C:\\Users\\Sana'a\\Downloads\\test.pdf"));
         d.open();
         PdfPTable table = new PdfPTable(1);
         table.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
         PdfPCell cell= new PdfPCell();
         cell.setBorder(Rectangle.NO_BORDER);
         Paragraph p= new Paragraph(jTextField1.getText(),arabic);
         Paragraph p2= new Paragraph("سناء علاء حسين",arabic);
         p.setAlignment(PdfPCell.ALIGN_LEFT);
         p2.setAlignment(PdfPCell.ALIGN_LEFT);
         cell.addElement(p);
         cell.addElement(p2);
         table.addCell(cell);
         d.add(table);
         d.close();
     }

     catch (Exception e) {
         System.out.println(e.getMessage());
     }

which prints some text to a PDF file, but the PDF shows some missing letters. For example: when I write (بيداء عبد الله) in the jtext, the PDF shows

بياء عب الله

and (سناء علاء حسين) becomes

سناء علاء حسي

any solution please.


Solution

  • Try using a font that covers the full range of Arabic characters such as Noto Naskh