How to solve an UnsupportedCharsetException when using itext-asian.jar?

Tags: AsianfontslanguagesiText 7pdfCalligraph

My Code:

public static final String[] tempString =
    { "KozMinPro-Regular.otf", "UniJIS-UCS2-H", pharseString };
bf = BaseFont.createFont(tempString[0], tempString[1], BaseFont.NOT_EMBEDDED);

The exception:

java.nio.charset.UnsupportedCharsetException: UniJIS-UCS2-H
        at java.nio.charset.Charset.forName(Unknown Source)
        at com.itextpdf.text.pdf.PdfEncodings.convertToBytes(
        at com.itextpdf.text.pdf.TrueTypeFont.<init>(
        at com.itextpdf.text.pdf.BaseFont.createFont(
        at com.itextpdf.text.pdf.BaseFont.createFont(
        at com.itextpdf.text.pdf.BaseFont.createFont(
        at de.vogella.itext.write.Main.addTextJapanese(
        at de.vogella.itext.write.Main.addContent(
        at de.vogella.itext.write.Main.main(
Posted on StackOverflow on Sep 14, 2014 by Han Kun

In iText 7 we create fonts like this:

PdfFont font = PdfFontFactory.createFont("KozMinPro-Regular", "UniJIS-UCS2-H", false);

If you want to use CJK fonts (the fonts that are not embedded and require a font pack in Adobe Reader), you should use KozMinPro-Regular (without the otf).

If you have a file named "KozMinPro-Regular.otf", you don't need the font-asian.jar (like itext-asian.jar in iText 5). Just use the font file with an encoding that is supported by that font program.

Click this link if you want to see how to answer this question in iText 5.