|
|
|
@ -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);
|
|
|
|
|