iText diacritic字符,如D,M等,在PDF上无法正确显示 [英] iText diacritic characters such as D̂, M̂ and so on not displayed correctly on PDF

查看:201
本文介绍了iText diacritic字符,如D,M等,在PDF上无法正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试创建包含标题中的字符的PDF时,我遇到了iText的问题。
会发生什么情况,重音circonflexe不能正确地位于字母上方,而是紧挨着它或者(取决于我使用的字体)稍微合并到它(请参阅下面我使用FreeSans的截图)。 / p>



我知道有这个问题的所有字符都是复合字符。我的意思是它们由两个unicode字符组成。例如,D表示为\ u0044 \ u0302,而所有通常的字符当然表示为\uXXXX。
所以我很确定它与此有关。
例如,具有正常unicode表示的Ê显示得很好。



这是一个很小的代码片段,希望包含你需要知道的一切:

 字符串TEXT =\ u0044 \ u0302 \ u004A \ u030C \ u004C \ u0302 \ u004D \\\̂ \\\N\\\̂ \\\d\\\̂ \\\l\\\̂ \\\m\\\̂ \\
\\\̂; //DJ̌LM N d l m n
BaseFont bf = BaseFont.createFont(FreeSans.ttf,BaseFont.IDENTITY_H,BaseFont.EMBEDDED);
document.add(new Paragraph(TEXT,font));

任何帮助都将受到高度赞赏。



提前致谢!

解决方案

您需要将iText 7与模块pdfCalligraph一起使用。这种构图需要访问OTF表以根据大小,高度等正确对齐字符。



有关 pdfCalligraph ,请参阅iText 7:积木教程的第2章(请滚到本章末尾)以了解它是如何工作的。您可以获得pdfCalligraph的免费试用版此处


I'm having a problem with iText when I'm trying to create a PDF that contains characters like the ones in the title. What happens is that the accent circonflexe does not sit properly above the letter but rather right next to it or (depending on what font I use) somewhat "merged" into it (see screenshot below where I used FreeSans).

I know that all the characters that have this problem are "composite" characters. What I mean by this is that they are composed of two unicode characters. For example the "D̂" is represented as "\u0044\u0302" whereas all the usual characters are of course represented as "\uXXXX". So I'm pretty sure that it has to do with this. For example an "Ê" which has a normal unicode representation is displayed just fine.

Here is a tiny code snippet that hopefully contains everything you need to know:

String TEXT = "\u0044\u0302 \u004A\u030C \u004C\u0302 \u004D\u0302 \u004E\u0302 \u0064\u0302 \u006C\u0302 \u006D\u0302 \u006E\u0302";//D̂ J̌ L̂ M̂ N̂ d̂ l̂ m̂ n̂
BaseFont bf = BaseFont.createFont("FreeSans.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
document.add(new Paragraph(TEXT, font));

Any help would be highly appreciated.

Thanks in advance!

解决方案

You'll need to use iText 7 with the module pdfCalligraph. This kind of composing requires access to the OTF tables to align correctly the chars depending on size, height, etc.

For more info on pdfCalligraph, see the chapter 2 of the "iText 7: building blocks" tutorial (please scroll towards the end of the chapter) to find out how it works. You can get a free trial version of pdfCalligraph here.

这篇关于iText diacritic字符,如D,M等,在PDF上无法正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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