我正在使用com.lowagie.text.FontFactory
生成PDF文件,并尝试使用自定义字体KozMinPro-Regular,它提供对日语字符的支持,因为我们有需要支持这一点。我在搜索中找到了一些示例,这些示例显示了如何执行此操作,与我在下面的操作类似,这些示例假设支持 UniJIS-UCS2-H 编码,但当我尝试此操作时,我收到了异常下面说不支持这种编码。如果有人对此有任何见解,我将不胜感激。谢谢
FontFactory.register("/usr/share/fonts/truetype/KozMinPro-Regular.ttf", "JapaneseCompatible");
contentFont = FontFactory.getFont("JapaneseCompatible", "UniJIS-UCS2-H", true, 11, Font.BOLD);
headerFont = FontFactory.getFont("JapaneseCompatible", "UniJIS-UCS2-H", true, 11, Font.BOLD);
我得到的异常:
Exception: [.ReportPdfView] Exception caught during generation of pdf file. Cause: UniJIS-UCS2-H
ExceptionConverter: java.io.UnsupportedEncodingException: UniJIS-UCS2-H
at java.lang.StringCoding.encode(StringCoding.java:286)
at java.lang.String.getBytes(String.java:954)
at com.lowagie.text.pdf.PdfEncodings.convertToBytes(Unknown Source)
at com.lowagie.text.pdf.TrueTypeFont.<init>(Unknown Source)
at com.lowagie.text.pdf.BaseFont.createFont(Unknown Source)
at com.lowagie.text.pdf.BaseFont.createFont(Unknown Source)
at com.lowagie.text.pdf.BaseFont.createFont(Unknown Source)
at com.lowagie.text.FontFactoryImp.getFont(Unknown Source)
at com.lowagie.text.FontFactoryImp.getFont(Unknown Source)
at com.lowagie.text.FontFactory.getFont(Unknown Source)
at com.lowagie.text.FontFactory.getFont(Unknown Source)
最佳答案
您需要iTextAsian.jar
。它提供 CJK 支持。
看...
http://itextpdf.sourceforge.net/对于早期版本的 iText 或
http://sourceforge.net/projects/itext/files/extrajars/适用于更高版本的 iText。(extrajars.zip 包含 iTextAsian.jar)
关于java - FontFactory (lowagie),Java,尝试使用 UniJIS-UCS2-H(日语)时出现 UnsupportedEncodingException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7165455/