Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unicode characters in iText PDF

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

like image 822
Bulit Avatar asked Mar 04 '12 16:03

Bulit


2 Answers

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.

like image 102
dotoree Avatar answered Sep 18 '22 14:09

dotoree


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.

like image 45
Kamil Avatar answered Sep 19 '22 14:09

Kamil