pdfbox版本
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.9</version>
</dependency>
覆盖FontMapperImpl类,如图所示
FontMapperImpl类中,将原来的ttf文件替换成自己需要的文件
//String ttfName = "org/apache/pdfbox/resources/ttf/LiberationSans-Regular.ttf";
String ttfName = "fonts/SimSun.ttf";
log.info("设置默认的字体");
URL url = FontMapper.class.getClassLoader().getResource(ttfName);
if (url == null) {
throw new IOException("Error loading resource: " + ttfName);
}
InputStream ttfStream = url.openStream();
TTFParser ttfParser = new TTFParser();
lastResortFont = ttfParser.parse(ttfStream);