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