【问题标题】:FontFactory (lowagie), Java, getting UnsupportedEncodingException when trying to use UniJIS-UCS2-H (for Japanese)FontFactory(lowagie),Java,尝试使用 UniJIS-UCS2-H(日语)时出现 UnsupportedEncodingException
【发布时间】: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


    【解决方案1】:

    您需要 iTextAsian.jar 。它提供 CJK 支持。

    看...

    http://itextpdf.sourceforge.net/ 用于早期版本的 iText 或

    http://sourceforge.net/projects/itext/files/extrajars/ 用于更高版本的 iText。(extrajars.zip 包含 iTextAsian.jar)

    【讨论】:

    猜你喜欢
    • 2014-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-10
    • 2011-09-08
    • 2018-06-24
    • 2011-05-22
    • 1970-01-01
    相关资源
    最近更新 更多