itextpdf中文不显示问题

原因1.没有指定中文字体

方法一:使用itext-asian
<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>itext-asian</artifactId>
    <version>5.2.0</version>
</dependency>

BaseFont baseFont = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
方法二:指定字体包地址
String fontPath = "font/simsunb.ttf";
BaseFont baseFont1 = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

 原因2:代码先后顺序问题

 正确示例:

Font contentFont = new Font(baseFont, 36, Font.NORMAL);
contentFont.setColor(BaseColor.BLACK);
Paragraph content = new Paragraph("Hello world!!你好!This is ...搁这搁这呢", contentFont);

 Error show:

Paragraph content = new Paragraph("Hello world!!你好!This is ...搁这搁这呢");
Font contentFont = new Font(baseFont, 36);
contentFont.setColor(BaseColor.BLACK);
content.setFont(contentFont);

相关推荐

  1. itextpdf显示问题

    2024-01-05 18:24:03       60 阅读
  2. 显示器显示清晰问题

    2024-01-05 18:24:03       120 阅读
  3. itextpdf 之 html 转 pdf 问题处理

    2024-01-05 18:24:03       55 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-05 18:24:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-05 18:24:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-05 18:24:03       87 阅读
  4. Python语言-面向对象

    2024-01-05 18:24:03       96 阅读

热门阅读

  1. React16源码: Hooks源码实现

    2024-01-05 18:24:03       51 阅读
  2. GreatSQL社区2023全年技术文章总结

    2024-01-05 18:24:03       60 阅读
  3. 7-24 约分最简分式 分数 15

    2024-01-05 18:24:03       56 阅读
  4. centos6后台启动docker

    2024-01-05 18:24:03       56 阅读
  5. 2401vim,vim重要修改更新大全

    2024-01-05 18:24:03       39 阅读
  6. 用RC2CryptoServiceProvider来加密解密

    2024-01-05 18:24:03       69 阅读
  7. 常用材料五行数据库超全汇总

    2024-01-05 18:24:03       54 阅读