java检测对应字体文件中包含的字符全集
1、引入pom
itext : '7.1.9'
implementation "com.itextpdf:kernel:${versions.itext}"
implementation "com.itextpdf:io:${versions.itext}"
implementation "com.itextpdf:layout:${versions.itext}"
implementation "com.itextpdf:forms:${versions.itext}"
implementation "com.itextpdf:font-asian:${versions.itext}"
implementation "com.itextpdf:html2pdf:${versions.itext}"
2、核心的实现
public void printAllchar() throws IOException {
String fontPath = "C:\\Users\\fengqingyang\\Desktop\\仿宋_GB2312.TTF";
try {
// 加载字体
FontProgram fontProgram = FontProgramFactory.createFont(fontPath);
PdfFont font = PdfFontFactory.createFont(fontProgram, PdfEncodings.IDENTITY_H);
// 获取字体支持的Unicode字符集
for (int code = 0; code <= Character.MAX_CODE_POINT; code++) {
if (fontProgram.getGlyph(code) != null) {
char character = (char) code;
System.out.println("Supported character: " + character + " Code: " + code);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
正文到此结束