新增检验报告打印接口
This commit is contained in:
31
src/main/java/com/dpkj/modules/print/utils/FontLoader.java
Normal file
31
src/main/java/com/dpkj/modules/print/utils/FontLoader.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.dpkj.modules.print.utils;
|
||||
|
||||
import com.itextpdf.text.pdf.BaseFont;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author 余文财
|
||||
* @description 字体加载
|
||||
* @date 2025.6.24
|
||||
*/
|
||||
public class FontLoader {
|
||||
public static BaseFont loadFont(String resourcePath) {
|
||||
try (InputStream fontStream = FontLoader.class.getResourceAsStream(resourcePath)) {
|
||||
if (fontStream == null) {
|
||||
throw new IllegalArgumentException("字体文件未找到: " + resourcePath);
|
||||
}
|
||||
// 创建支持中文的 BaseFont
|
||||
return BaseFont.createFont(
|
||||
resourcePath,
|
||||
BaseFont.IDENTITY_H,
|
||||
BaseFont.EMBEDDED,
|
||||
false,
|
||||
fontStream.readAllBytes(),
|
||||
null
|
||||
);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("字体加载失败: " + resourcePath, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user