iText在pdf中变形/拼写错误的Unicode字符 [英] iText is deforming/misspelling Unicode characters in pdf

查看:910
本文介绍了iText在pdf中变形/拼写错误的Unicode字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用iText v2.1.5生成一个pdf,它基本上包含Unicode字符,Ariel是用于相同的字体。现在问题是像印地语和古吉拉特语字符这样的一些字符正在正确生成问题。请看下面的截图,以便更好地理解这个问题。

I am trying to generate a pdf using iText v2.1.5 which basically contains Unicode characters, Ariel is the font being used for the same. Now the problem is that some of the characters like the "Hindi" and "Gujarati" characters are having issues being generated properly. Please take a look at the below screenshot to understand the issue better.

图表和表格中突出显示的字体都使用相同的字体,但表格中的字体是不适合印地文和古贾尔蒂字符。

Both the highlighted fonts in the Graph and Table use the same fonts, but the font in the table are not proper for hindi and gujarti characters.

图表中的突出显示字符(融合图表)是使用PhantomJS生成的,并作为png图像嵌入pdf中。下表中的字符具有与图中使用的字体相同的Arial_Unicode_MS.ttf字体(在linux机器中的/usr/share/fonts/truetype/Arial_Unicode_MS.ttf中可用),但生成的表格使用iText,我无法弄清楚为什么会导致这种意外行为。

The highlighted characters in the Graph(fusion charts) are generated using PhantomJS and embedded in the pdf as a png image. The characters in the Table below have the same "Arial_Unicode_MS.ttf" font (available at /usr/share/fonts/truetype/Arial_Unicode_MS.ttf in the linux machine) as that of the ones used in the Graph, but the table is generated using iText and I can't figure out why this is resulting in such unexpected behaviour.

我试过调试phantomJS,我可以保证它使用上面提到的相同字体文件。请参考我在iText中的代码:

I tried debugging phantomJS and I can assure that it uses the same font file mentioned above. Please refer the code below that I have in iText :

String formattedData="જિજ્ઞેશ";
BaseFont nationalBase = BaseFont.createFont("/usr/share/fonts/truetype/Arial_Unicode_MS.ttf", BaseFont.COURIER, BaseFont.NOT_EMBEDDED);
PdfPCell dataCell= new PdfPCell(new Phrase(8, new Chunk(formattedData, dataFont)));

要检查问题是否是因为iText我尝试使用formattedData =Unicode中的Unicode字符直接,生成的表格中反映的字体仍然与我最初使用的字体有很大不同。

To check if the issue is because of iText I tried using the Unicode characters in the formattedData="જિજ્ઞેશ" directly, still the font's reflected in the table generated differ a lot that what I originally used.

推荐答案

正如之前多次解释的那样,iText 5不支持印地语。我们在iText 7中解决了这个问题,我们在印度的大印度开发者峰会上发布了该版本

As explained many times before, iText 5 doesn't support Hindi. We fixed this in iText 7 and we released that version in India at the Great Indian Developer Summit.

iText 7有一个特殊的附加组件,名为 pdfCalligraph ,一旦你插入这个附加组件,Devaganari和Tamil将被正确呈现。请阅读 iText 7:Building Blocks的第2章(请滚动到本章末尾)以了解pdfCalligraph插件的工作原理。您可以获得pdfCalligraph的免费试用版此处

iText 7 has a special add-on, named pdfCalligraph and as soon as you plug in this add-on, Devaganari and Tamil will be rendered correctly. Please read Chapter 2 of "iText 7: Building Blocks" (please scroll towards the end of the chapter) to find out how the pdfCalligraph add-on works. You can get a free trial version of pdfCalligraph here.

目前支持梵文,泰米尔语和阿拉伯语。将根据付费客户的要求添加对其他书写系统的支持。

Currently Devanagari, Tamil and Arabic are supported. Support for other writing systems will be added at the request of paying customers.

这篇关于iText在pdf中变形/拼写错误的Unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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