iText 5.5.3 PDFPCell : long text doesn't fit c

2019-04-10 14:07发布

问题:

i am trying to create a Persian PDF containing tables and i want to write in it. when my string is long it doesn't fit the cell correctly. feels like String fills the cell upside down!... i mean for example when i want to write "hello my friend . what's up?" in the cell the output is like this:


| what's up? |

| my friend |

| hello |


but of course in Persian (it's Ok in English)

here i attached the code by the way

        private  LanguageProcessor al = new ArabicLigaturizer();
        cell = new PdfPCell(new Phrase(al.process(persian_text), fontNormal));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setBorderWidth(0);
        table.addCell(cell);

i would be thankful with your help

回答1:

First this: iText 5.5.5 doesn't exist (yet). You are probably using another version.

As for your problem: you are using the wrong approach. The correct approach is explained in the answer to "how to create persian content in pdf using eclipse."

PdfPCell cell = new PdfPCell(new Phrase(arabic_text, fontNormal));
cell.setVerticalAlignment(Element.ALIGN_TOP);
cell.setBorderWidth(0);
cell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
table.addCell(cell);

You should not use ArabicLigaturizer directly! In the above code snippet, arabic_text is the original String with the Arabic characters. Note that you should not use Unicode characters in your source code. See the second observation in my answer to this question: Can't get Czech characters while generating a PDF



标签: java pdf itext