ln_ry20250512
dshclm 3 weeks ago
parent caf9f27b80
commit c0341d8884

@ -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.HashMap;
import java.util.Map;
@ -63,9 +63,11 @@ public class PdfService {
try {
// 加载模板PDF
ClassLoader classLoader = getClass().getClassLoader();
File templateFile = new File(classLoader.getResource("static/file/pdf/smryscb.pdf").getFile());
document = PDDocument.load(templateFile);
InputStream templateStream = getClass().getClassLoader().getResourceAsStream("static/file/pdf/smryscb.pdf");
if (templateStream == null) {
throw new IOException("无法找到模板PDF文件");
}
document = PDDocument.load(templateStream);
PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
if (acroForm == null) {
@ -73,9 +75,8 @@ public class PdfService {
}
// 加载中文字体
PDType0Font font = PDType0Font.load(document,
new File(classLoader.getResource("static/file/pdf/STSONG.TTF").getFile()));
InputStream fontStream = getClass().getClassLoader().getResourceAsStream("static/file/pdf/STSONG.TTF");
PDType0Font font = PDType0Font.load(document, fontStream);
// 设置需要更新表单外观
acroForm.setNeedAppearances(true);

Loading…
Cancel
Save