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

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

问题描述

我们有一个grails应用程序,我们使用渲染插件来渲染.pdf中的内容。这一切都适用于英语,但不幸的是,对于阿拉伯语(我们必须呈现),所有字词似乎都破碎。一些数字和空格在那里......



渲染插件使用IText,我尝试了这种方法:



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

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



任何人都有这类问题的经验?

预先感谢您!

解决方案

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

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



是的。 Google代码为您使用的addFont生成了以下代码:

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

IDENTITY_H让您可以定位给定字体中的所有字形。我总是推荐它,虽然有一个小缺点。使用IDENTITY_H会强制字体成为iText中的一个嵌入子集,无法绕过它。


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.

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

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