Generating pdf with utf characters

2,652 views
Skip to first unread message

Danilo Cubrovic

unread,
May 24, 2011, 8:28:45 AM5/24/11
to Flying Saucer Users
I'm new user of this great library.Pretty impressed with what I've
seen so far.

I'm having only one , but dealbreaking, problem.

This is issue with generating pdf with some foreign latin characters
in it.
I'm pretty sure I'm doing something wrong but dont know what.

When I generate pdf with code like this

ITextRenderer renderer = new ITextRenderer();
ITextFontResolver fontResolver = renderer.getFontResolver();
fontResolver.addFont("/fs/build/ekspert/
lsansuni.ttf",BaseFont.IDENTITY_H, true);
renderer.setDocumentFromString(txt);
renderer.layout();
renderer.createPDF(os);

it goes without errors but my characters still missing

When I open this pdf file and add paragraph with same text string and
font it goes well ?!

BaseFont baseFont = BaseFont.createFont("/fs/build/ekspert/
lsansuni.ttf", BaseFont.IDENTITY_H, true);
Font font = new Font(baseFont, 12);
Document pdfDocument = new Document();
PdfWriter.getInstance(pdfDocument, new FileOutputStream(RESULT2));
pdfDocument.open();
Paragraph p1 = new Paragraph(new Chunk(txt, font));
pdfDocument.add(p1);
pdfDocument.close();

But this method 2 is only good for trivial one paragraph test, cant
generate pdf from my big html files that way :(

I have tryed some other arguments in addFont method in first example.
Didnt help.
Does anybody have idea what I'm doing wrong?

(BTW using it, now, on Kubunutu Linux distro. Will be moved to FreeBsd
server later.)

Thanks in advance.

Peter Brant

unread,
May 24, 2011, 10:20:15 AM5/24/11
to flying-sa...@googlegroups.com
You do need to reference the font in your CSS somewhere. For example,

<div style="font-family: "Lucida Sans Unicode">...

(assuming that's the right family name)

Pete

Danilo Cubrovic

unread,
May 24, 2011, 2:28:08 PM5/24/11
to Flying Saucer Users
Yup that's the stuff that missing in all those examples :)
Thanks a lot Peter!
Reply all
Reply to author
Forward
0 new messages