ln_ry20250512
dshclm 2 days ago
parent c0341d8884
commit 693b8982fe

@ -12,9 +12,10 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
@Service
public class ChangePdfService {
// 定义最大和最小字体大小,用于动态调整
@ -41,8 +42,11 @@ public class ChangePdfService {
try {
// 加载模板PDF
ClassLoader classLoader = getClass().getClassLoader();
File templateFile = new File(classLoader.getResource("static/file/pdf/smrydlgwspb.pdf").getFile());
document = PDDocument.load(templateFile);
InputStream templateStream = classLoader.getResourceAsStream("static/file/pdf/smrydlgwspb.pdf");
if (templateStream == null) {
throw new IOException("无法找到PDF模板文件");
}
document = PDDocument.load(templateStream);
PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
if (acroForm == null) {
@ -50,8 +54,11 @@ public class ChangePdfService {
}
// 加载中文字体
PDType0Font font = PDType0Font.load(document,
new File(classLoader.getResource("static/file/pdf/STSONG.TTF").getFile()));
InputStream fontStream = classLoader.getResourceAsStream("static/file/pdf/STSONG.TTF");
if (fontStream == null) {
throw new IOException("无法找到字体文件");
}
PDType0Font font = PDType0Font.load(document, fontStream);
// 设置需要更新表单外观
acroForm.setNeedAppearances(true);

@ -12,8 +12,8 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
@Service
@ -26,7 +26,7 @@ public class LeavePdfService {
private static final float ESTIMATED_FIELD_WIDTH = 100f;
// 需要特殊处理的字段列表
private static final String[] AUTO_WRAP_FIELDS = {
"涉密岗位","职务职级","姓名","政治面貌"
"涉密岗位","职务职级","姓名","政治面貌"
};
public ByteArrayOutputStream fillForm(Map<String, String> formData,
@ -43,8 +43,11 @@ public class LeavePdfService {
try {
// 加载模板PDF
ClassLoader classLoader = getClass().getClassLoader();
File templateFile = new File(classLoader.getResource("static/file/pdf/smrylzlgspb.pdf").getFile());
document = PDDocument.load(templateFile);
InputStream templateStream = classLoader.getResourceAsStream("static/file/pdf/smrylzlgspb.pdf");
if (templateStream == null) {
throw new IOException("无法找到PDF模板文件");
}
document = PDDocument.load(templateStream);
PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
if (acroForm == null) {
@ -52,8 +55,11 @@ public class LeavePdfService {
}
// 加载中文字体
PDType0Font font = PDType0Font.load(document,
new File(classLoader.getResource("static/file/pdf/STSONG.TTF").getFile()));
InputStream fontStream = classLoader.getResourceAsStream("static/file/pdf/STSONG.TTF");
if (fontStream == null) {
throw new IOException("无法找到字体文件");
}
PDType0Font font = PDType0Font.load(document, fontStream);
// 设置需要更新表单外观
acroForm.setNeedAppearances(true);

Loading…
Cancel
Save