Skip to main content
Skip table of contents

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

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(PdfEncodings.java:186)
        at com.itextpdf.text.pdf.TrueTypeFont.init>(TrueTypeFont.java:376)
        at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:705)
        at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:621)
        at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:456)
        at de.vogella.itext.write.Main.addTextJapanese(Main.java:145)
        at de.vogella.itext.write.Main.addContent(Main.java:134)
        at de.vogella.itext.write.Main.main(Main.java:254)

Posted on StackOverflow on Sep 14, 2014 by Han Kun

The cause of the exception that is thrown can be found in the following lines:

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

Either you have a font program named KozMinPro-Regular.otf, or you want to use the font KozMinPro-Regular.

If you have a file named KozMinPro-Regular.otf, you don't need the iText-Asian.jar. Just use the font file with an encoding that is supported by that font program. UniJIS-UCS2-H is not supported by that OpenType font.

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).

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

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.