【发布时间】:2011-11-02 04:30:28
【问题描述】:
我正在使用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)
【问题讨论】:
标签: java pdf unicode fonts itext