Grails/RenderPdf 阿拉伯字符 [英] Grails / RenderPdf Arabic Chars

查看:40
本文介绍了Grails/RenderPdf 阿拉伯字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个 grails 应用程序,我们在其中使用了 渲染插件以 .pdf 格式渲染内容.这对英语来说一切正常,但不幸的是,对于阿拉伯语(我们必须呈现),所有字符似乎都损坏"了.那里有一些数字和空格...

We have a grails app, in which we are using the Render Plugin to render content in .pdf. It all works fine for English, but unfortunately for Arabic (which we must render) all the charactes seem "broken". Some numbers and spaces there...

渲染插件使用 IText,我尝试了以下方法:

The render plugin uses IText, and I have tried the approach with:

...  
def renderer = new ITextRenderer()  
FontResolver resolver = renderer.getFontResolver()  
renderer.getFontResolver().addFont("/usr/share/fonts/truetype/ttf-arabeyes/ae_AlArabiya.ttf", BaseFont.EMBEDDED)  
...

(这里使用的字体只是一个例子),但无论如何,它不起作用.

(the font used here is just an example), but in any case, it doesn't work.

有人遇到过这种问题吗?

Anybody any experience with this kind of issue?

先谢谢你!

推荐答案

renderer.getFontResolver.addFont(fontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED_SUBSET);

iText 中字体的默认编码是 WinAnsiEncoding,AKA Code Page 1252.您需要指定包含您想要的字符的编码...

The default encoding for fonts in iText is WinAnsiEncoding, AKA Code Page 1252. You need to specify an encoding that contains the characters you want...

是的.Google Code 为您使用的 addFont 生成了这段代码:

Yep. Google Code produced this bit of code for the addFont you're using:

public void addFont(String path, boolean embedded)
        throws DocumentException, IOException {
    addFont(path, BaseFont.CP1252, embedded);
}

IDENTITY_H 可让您处理给定字体中的所有字形.我总是推荐它,尽管有一个小缺点.使用 IDENTITY_H 强制字体成为 iText 中的嵌入子集,无法绕过它.

IDENTITY_H lets you address all the glyphs in a given font. I always recommend it, though there is a small drawback. Using IDENTITY_H forces the font to be an embedded subset in iText, no way around it.

这篇关于Grails/RenderPdf 阿拉伯字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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