Unicode characters in iText PDF

2019-05-04 21:43发布

I need help with iText I look at some Google result and some here but don't find anything that work for me. I need to use polish character in my pdf but i got nothing for no. Here is a code that I think is important if need something else write in comment:

private static Font bigFont = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD);

another

Paragraph par = new Paragraph(Łabadzak, bigFont);

Can any1 tell me what to do to make that Ł visible in pdf and other polish character

UPDATE I fund this but dunno how to use it for my project Polish character in itext PDF

2条回答
霸刀☆藐视天下
2楼-- · 2019-05-04 22:26

It depends on used font and encoding. i found something like this:

http://itext-general.2136553.n4.nabble.com/Polish-National-Characters-are-not-getting-displayed-in-the-PDF-created-by-iTExt-td2163833.html

There is example like this:

BaseFont bf = BaseFont.createFont("c:/windows/fonts/arial.ttf", 
BaseFont.CP1250, BaseFont.EMBEDDED); 
Font font = new Font(bf, 12); 
String polish = "\u0104\u0105\u0106\u0107\u0118\u0119"; 
document.add(new Paragraph(polish, font)); 

Remember that some fonts does not contain polish national characters.

查看更多
再贱就再见
3楼-- · 2019-05-04 22:32

You need a unicode font. Here is an example:

BaseFont bf = BaseFont.createFont("arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

Paragraph p = new Paragraph("Şinasi ıssız ile ağaç", new Font(bf, 22));

document.add(p);

http://abdullahakay.blogspot.com/2011/11/java-itext-unicode.html

EDIT:

Here, the font file name arialuni.tff is a static resource directly under /src/main/resources/ and can be any Unicode Font File of your choice. Here's a list of free Unicode Font Files available online.

查看更多
登录 后发表回答