检查报告打印
This commit is contained in:
@@ -2,6 +2,8 @@ package com.dpkj.modules.print.utils;
|
||||
|
||||
import com.itextpdf.text.pdf.BaseFont;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
@@ -15,17 +17,27 @@ public class FontLoader {
|
||||
if (fontStream == null) {
|
||||
throw new IllegalArgumentException("字体文件未找到: " + resourcePath);
|
||||
}
|
||||
// 创建支持中文的 BaseFont
|
||||
byte[] fontBytes = toByteArray(fontStream);
|
||||
return BaseFont.createFont(
|
||||
resourcePath,
|
||||
BaseFont.IDENTITY_H,
|
||||
BaseFont.EMBEDDED,
|
||||
false,
|
||||
fontStream.readAllBytes(),
|
||||
fontBytes,
|
||||
null
|
||||
);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("字体加载失败: " + resourcePath, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] toByteArray(InputStream input) throws IOException {
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
int nRead;
|
||||
byte[] data = new byte[4096];
|
||||
while ((nRead = input.read(data, 0, data.length)) != -1) {
|
||||
buffer.write(data, 0, nRead);
|
||||
}
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user