Special characters in iText

Tag: pdf , character-encoding , itext , symbols Author: lijunjndx Date: 2010-09-04

I need help in using these symbols ?, ?, ?, ?, and so on. But when I create a PDF with iText these symbols do not appear.

What can I do so that these symbols appear?

Other Answer1

You have to use a font and encoding that contains those characters. Your best bet is to use IDENTITY_H for your encoding, as this grants you access to every character within a given font... but you still have to use the right font.

There are several font-manipulation examples within "iText in Action's" chapter on fonts: http://www.itextpdf.com/book/chapter.php?id=11

The examples are down the right side. Buying the book would probably help too.


here is an example that shows you how to set the encoding itextpdf.com/examples/iia.php?id=164 utf8 generally works for me
10x. helped me after 2 years !

Other Answer2

I have also had the same problem, and I figured out using IDENTITY_H for encoding is working fine. For example:

Font font = FontFactory.getFont(f.getName(),BaseFont.IDENTITY_H)

I don't understand why with BaseFont.WINANSI it doesn't work. Winansi is the standard Windows Cp1252 character set, that one used by my JVM. So, if the char is correctly displayed in Java, why it is not the case for PDF?

Other Answer3

You can escape them according to the unicode escape sequence defined in the java language specification. See http://java.sun.com/docs/books/jls/first_edition/html/3.doc.html

If you are using IntelliJ IDEA for your code you can download the StringManipulation plugin, that does the escapes for you. In the settings of IDEA you can also set the "Transparent native-to-ascii conversion" checkbox under File encodings, and this should help do the trick.


I use this encoding for characters but iText doesn't show them. I want to work in GAE.
Have you tried escaping the characters?