我在iText中的希伯来语文本是左对齐的 [英] My Hebrew Text in iText is left-aligned

查看:424
本文介绍了我在iText中的希伯来语文本是左对齐的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码在iText中生成希伯来语文本。

I am using the following code to generate Hebrew text in iText.

它运行良好(创建希伯来语字体,并使文本从右到右流动左)但是文字是左对齐而不是右对齐。

It works nicely (creates a Hebrew font, and makes the text flow from right-to-left) but the text is left-aligned rather than right-aligned.

任何人都可以帮助我使其正确对齐吗?请注意,我试图使MultiColumnText右对齐,并且段落右对齐 - 但无效!

Can anyone help me make it right-aligned? Notice that I tried to make the MultiColumnText right-aligned, and the paragraph right-aligned - but to no avail!

谢谢

static Color darkBlue = new Color(0x2F, 0x36, 0x99);
BaseFont unicode = BaseFont.createFont("c:/windows/fonts/arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font fontDarkBlueHebrew = new Font(unicode, 12, Font.NORMAL,darkBlue);

MultiColumnText mct=new MultiColumnText();
mct.addSimpleColumn(36, PageSize.A4.width()-36);
mct.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
mct.setAlignment(Element.ALIGN_RIGHT);

Paragraph section1a = new Paragraph("כותרת 1",fontDarkBlueHebrew );
section1a.setAlignment(Element.ALIGN_RIGHT);            
mct.addElement(section1a);

Paragraph section1b = new Paragraph("הטקסט שלע",fontDarkBlueHebrew);
section1b.setAlignment(Element.ALIGN_RIGHT);  
mct.addElement(section1b);

document.add(mct);


推荐答案

这是设计的。当改变书写方向时,一切都颠倒过来:左边变成右边,右边变成左边。所以你需要 Element.ALIGN_LEFT 而不是 Element.ALIGN_RIGHT

This is by design. When changing the writing direction, everything is reversed: left becomes right and right becomes left. So you need Element.ALIGN_LEFT instead of Element.ALIGN_RIGHT.

这篇关于我在iText中的希伯来语文本是左对齐的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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