iText 5.5.3 PDFPCell:长文本不适合单元格(不正确地包装文本) [英] iText 5.5.3 PDFPCell : long text doesn't fit corrctly in cell (wrap text incorrectly)

查看:269
本文介绍了iText 5.5.3 PDFPCell:长文本不适合单元格(不正确地包装文本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个包含表格的波斯语PDF,我想写入其中。当我的字符串很长时,它不能正确地适合单元格。感觉像字符串填充单元格颠倒!...我的意思是例如当我想写你好我的朋友。什么事情?单元格中的
输出如下:

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? |

|我的朋友|

|你好|

当然是波斯语(英语好的)

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

这里我顺便附上了代码

        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);

我会感谢您的帮助

推荐答案

首先:iText 5.5.5不存在(尚未)。您可能正在使用其他版本。

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

至于您的问题:您使用的是错误的方法。在如何创建波斯语的答案中解释了正确的方法pdf中的内容使用eclipse

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);

您不应直接使用 ArabicLigaturizer !在上面的代码段中, arabic_text 是带有阿拉伯字符的原始字符串。请注意,您不应在源代码中使用Unicode字符。请参阅我对这个问题的回答中的第二个观察结果:无法获得捷克语生成PDF时的字符

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

这篇关于iText 5.5.3 PDFPCell:长文本不适合单元格(不正确地包装文本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆