For itextpdf to generate Chinese normally, you need a jar package. The easiest way is to download it from the maven library.
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.10</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
Add the following two dependencies.
BaseFont font = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Note: Before itext5, the com.lowagie package was used, and then the package name was changed to com.itextpdf, don't confuse it, or an error will be reported:
Font 'STSong-Light' with 'UniGB-UCS2-H' is not recognized.
Welcome to the iTextPDF China exchange group: 554713439