如何使用java在itext中检测不同的语言?

时间:2022-05-15 21:08:17

The user enters his details in a registration form.So the user can enter either in english or arabic.My requirement is if he enters arabic i need to detect that and set the font and direction to RTL.IF its english it shud display as it is.I know how to set the font.But i dont know how to set the direction for the string.It should change direction for arabic only.

用户可以在注册表中输入他的详细信息。因此用户可以输入英语或阿拉伯语。我的要求是如果他进入阿拉伯语我需要检测到并将字体和方向设置为RTL.IF其英语显示为shud是。我知道如何设置字体。但我不知道如何设置字符串的方向。它应该只改变阿拉伯语的方向。

BaseFont bf = BaseFont.createFont("C:\\WINDOWS\\Fonts\\ARIALUNI.TTF",BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font font = new Font(bf, 10, 0);
String arab="آزمايش";
document.add(new Chunk(arab, font));

The above code writes the arabic text in the pdf in reverse. How do i set the direction for that string?So in short my requirement is to write the string value correctly if its english from LTR ,if its arabic from RTL.Could some1 help me with this?Thanks.

上面的代码将pdf中的阿拉伯文本反向写入。我如何设置该字符串的方向?所以简而言之,我的要求是如果它的英语来自LTR正确写入字符串值,如果它来自RTL的阿拉伯语。可以帮助我解决这个问题吗?谢谢。

1 个解决方案

#1


0  

you can check the result of this regex:

你可以查看这个正则表达式的结果:

"[\u0600-\u06FF,\u0590-\u05FF]"

If the result is true, the string "contains" a RTL word (Arabic/Persian/Hebrew)

如果结果为true,则字符串“包含”RTL字(阿拉伯语/波斯语/希伯来语)

#1


0  

you can check the result of this regex:

你可以查看这个正则表达式的结果:

"[\u0600-\u06FF,\u0590-\u05FF]"

If the result is true, the string "contains" a RTL word (Arabic/Persian/Hebrew)

如果结果为true,则字符串“包含”RTL字(阿拉伯语/波斯语/希伯来语)