Grails / RenderPdf Arabic Chars

孤街醉人 提交于 2019-12-11 07:55:38

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/5366990/grails-renderpdf-arabic-chars

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!