3

I am trying to insert a checkbox character into my pdf like this :

Phrase phrase = new Phrase("\u2610 somemoretext", somefont);

The "somemoretext"-portion of the String is beeing displayed correctly, the checkbox character isn´t. Do i have to use something specific as a Font for this character, or what else could I be doing wrong?

Jannis Alexakis
  • 1,279
  • 4
  • 19
  • 38

2 Answers2

3

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:

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

but you still have to use the right font. This link could prove to be of help to you too

EDIT:

I also see different Fonts use different conversion codes/sequences:

Use a corresponding character in a different font. For instance in Wingdings.ttf you have 0x6F and 0x70

David Kroukamp
  • 36,155
  • 13
  • 81
  • 138
  • @sMaN As per the docs the first parameter is a `String` which is the name of the Font Family i.e `getFont(FontFactory.HELVETICA,13)` where `FontFactory.HELVETICA` is the font families name and 13 is the size of the font. Read the docs they ill help you understand the necessary parameters of methods etc. Another example is `FontFactory.getFont("Arial", 8, Font.ITALIC)` – David Kroukamp Nov 14 '13 at 18:03
  • So in the given example, the variable 'f' is an instance of Font, therefor f.getName() returns the string representation of the font name. I just couldn't see the variable f defined or instanciated anywhere in the examples. Thanks. – sMaN Nov 17 '13 at 22:56
0
var font = FontFactory.GetFont(@"C:\Windows\Fonts\wingding.ttf", BaseFont.CP1252, true, 12);
Phrase phrase = new Phrase("\xFC somemoretext", font);

Inspired by https://stackoverflow.com/a/5044017/1021364

Character map

enter image description here

check: FB

tick: FC

check in checkbox: FD

tick in checkbox: FE

empty checkbox: 6F

Community
  • 1
  • 1
  • 1
    While the op did not mention that he works on windows and, therefore, WinDings are not necessarily available, the generalised tip to look for a font containing the desired characters is applicable. – mkl Nov 02 '16 at 11:29