0

I am creating a PDF with Arabic & latin mixed data. The arabic comes out unshaped. The code i have is like the Ligatures2 example:

PdfPTable table = new PdfPTable(1);                           
table.setWidthPercentage(100);                                
table.getDefaultCell().setBorder(0);                          
table.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);  
 ColumnText column = new ColumnText(writer.getDirectContent());         
 column.setSimpleColumn(0, 0, 1500, 1500);                       
column.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
 document.add(new Paragraph(line, font));                   
 column.go();                
user1579878
  • 107
  • 7

1 Answers1

0

I'm sorry to disagree with you, but your code is nothing like the Ligatures2 example:

  • You create a PdfPTable object, but you don't add any content to it. You don't add the table to the document.
  • You create a ColumnText object, but you don't add any content to it. When you perform go() nothing happens.

If we remove all the unused lines from your code snippet, this is what remains:

document.add(new Paragraph(line, font)); 

As documented in the book that comes with the Ligatures2 example you refer to, this code, this is insufficient to render Arabic.

One way to fix your code would be to do something like this:

ColumnText column = new ColumnText(writer.getDirectContent());         
column.setSimpleColumn(36, 36, 559, 806);                       
column.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
document.addElement(new Paragraph(line, font));                   
column.go();

Note that I am making an assumption here: I assume that your page size is A4. In your code, you defined the rectangle of the column like this:

column.setSimpleColumn(0, 0, 1500, 1500);

That's a very strange size.

Side-note:

Please avoid to copy/paste code from examples and then break those examples without reading the documentation that comes with the examples. I see that (1.) this question isn't the first example of this behavior, and (2.) you don't provide feedback when somebody answers your question. If a question is solved correctly, you should do the right thing and accept the answer!

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