开发者

Grails / RenderPdf Arabic Chars

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

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?

Thank you in开发者_开发百科 advance!


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

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜