I have some custom Chinese font files:
aaa.ttf
bbb.ttf
ccc.ttf
And I want to use them to create my pdf with iText.
This is the code I use to create a BaseFont
:
String encoding = ???
BaseFont messageBaseFont = BaseFont.createFont("fonts/aaa.ttf",
encoding,
BaseFont.EMBEDDED);
But I don't know how to find the encoding
. Take aaa.ttf
for example:
Can I find the encoding
from the information? I tried some encodings like BaseFont.CP1252
or BaseFont.WINANSI
, but they didn't work, the output are blank page or a lot of ??????
characters if they are Chinese characters.
There are different answers to this question. For a full overview, you could read chapter 11 of my book, "iText in Action", but if you just want to be safe, use Identity-H for horizontal text (and Identity-V). This isn't really an encoding, but it will create a composite font in the PDF that uses Unicode: http://api.itextpdf.com/itext/com/itextpdf/text/pdf/BaseFont.html#IDENTITY_H
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With