2
我使用com.lowagie.text.FontFactory
生成PDF文件,並試圖使用自定義字體KozMinPro-Regular,它提供支持對於日文字符,因爲我們需要支持這一點。我發現搜索的例子顯示瞭如何做到這一點,類似於我下面的做法,這些例子假設支持UniJIS-UCS2-H
編碼,但是當我嘗試這樣做時,我得到了下面的異常,表示不支持此編碼。如果有人對此有所瞭解,我將不勝感激。由於FontFactory(lowagie),Java,在嘗試使用UniJIS-UCS2-H(用於日語)時得到UnsupportedEncodingException
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)
這是更好地從Maven的得到它, https://mvnrepository.com/artifact/com.itextpdf/itext-asian,因爲iText Softare不再使用SourceForge。 –