使用itext生成pdf,在linux环境下,中文全部失踪,因为itext要在linux下支持中文字体需要引入itext-asian, 并添加一个字体类。

 public static class PdfFont extends XMLWorkerFontProvider{
        public PdfFont(){
            super(null,null);
        }
        @Override
        public Font getFont(final String fontname, String encoding, float size, final int style) {

            Font FontChinese = null;
            try {
                BaseFont bfChinese = BaseFont.createFont("STSong-Light",
                        "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
                FontChinese = new Font(bfChinese, 12, Font.NORMAL);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if(FontChinese==null)
                FontChinese = super.getFont(fontname, encoding, size, style);
            return FontChinese;
        }}

 

相关文章:

  • 2021-09-23
  • 2022-01-10
  • 2022-02-14
  • 2021-11-07
  • 2021-11-10
  • 2021-12-04
  • 2021-12-18
猜你喜欢
  • 2021-11-11
  • 2021-06-18
  • 2021-04-18
  • 2021-08-10
  • 2021-06-28
  • 2021-08-14
相关资源
相似解决方案