package org.jeecg.modules.system.util;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.demo.st.entity.StAwards;
import org.jeecg.modules.demo.st.entity.StScholarships;
import org.jeecg.modules.demo.st.entity.StStudent;
import org.jeecg.modules.demo.st.service.IStClassService;
import org.jeecg.modules.demo.st.utils.PdfUtils;
import org.jeecg.modules.system.service.ISysDepartService;
import org.jeecg.modules.system.service.ISysDictService;
import reactor.core.publisher.Flux;
import java.util.*;
public class GetStuPdf {
public static void getPdf(StStudent stStudent,
ISysDictService sysDictService,
IStClassService stClassService,
List<StAwards> stAwards,
StScholarships stScholarships,
ISysDepartService sysDepartService) {
Map<String, String> map = new HashMap();
map.put("college", sysDepartService.queryByIdCollges(stStudent.getCollege()));
map.put("student_id", stStudent.getStudentId());
map.put("st_name", stStudent.getStName());
map.put("sex", sysDictService.queryDictTextByKey("sex", stStudent.getSex()));
map.put("face", sysDictService.queryDictTextByKey("face", stStudent.getFace()));
map.put("nationality", sysDictService.queryDictTextByKey("nation", stStudent.getNationality()));
map.put("st_class", stClassService.queryByIdClas(stStudent.getStClass()));
map.put("phone", stStudent.getPhone());
map.put("st_card", stStudent.getStCard());
map.put("grades_ranking", stScholarships.getGradesRanking());
map.put("evaluation", stScholarships.getEvaluation());
map.put("compulsory", stScholarships.getCompulsory());
map.put("pass", stScholarships.getPass());
map.put("rank", stScholarships.getRank());
map.put("application", stScholarships.getApplication());
map.put("recommend", stScholarships.getRecommend());
map.put("hospital", stScholarships.getHospital());
map.put("school", stScholarships.getSchool());
map.put("xuezhi", stStudent.getXuezhi());
map.put("chushengriqi", stStudent.getChushengriqi());
map.put("ruxueshijian", stStudent.getRuxueshijian());
List<Map<String, String>> mapList = new ArrayList<>();
for (int i = 0; i < stAwards.size(); i++) {
Map<String, String> map2 = new HashMap();
map2.put("time", stAwards.get(i).getTime());
map2.put("award_name", stAwards.get(i).getAwardName());
map2.put("awarding_unit", stAwards.get(i).getAwardingUnit());
mapList.add(map2);
}
Map<String, Object> o = new HashMap();
o.put("datemap", map);
o.put("planList", mapList);
PdfUtils.pdfout(o);
}
}
package org.jeecg.modules.demo.st.utils;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import org.jeecg.modules.demo.st.entity.StStudent;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class PdfUtils {
public static void pdfout(Map<String, Object> o) {
String templatePath = "C:/Users/fisherman/Desktop/xzmb1.pdf";
String newPDFPath = "C:/Users/fisherman/Desktop/xz1.pdf";
PdfReader reader;
FileOutputStream out;
ByteArrayOutputStream bos;
PdfStamper stamper;
try {
BaseFont bf = BaseFont.createFont("c://windows//fonts//simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font FontChinese = new Font(bf, 5, Font.NORMAL);
out = new FileOutputStream(newPDFPath);
reader = new PdfReader(templatePath);
bos = new ByteArrayOutputStream();
stamper = new PdfStamper(reader, bos);
AcroFields form = stamper.getAcroFields();
Map<String, String> datemap = (Map<String, String>) o.get("datemap");
form.addSubstitutionFont(bf);
for (String key : datemap.keySet()) {
String value = datemap.get(key);
form.setField(key, value);
}
stamper.setFormFlattening(true);
stamper.close();
Document doc = new Document();
Font font = new Font(bf, 32);
PdfCopy copy = new PdfCopy(doc, out);
doc.open();
PdfImportedPage importPage = copy.getImportedPage(new PdfReader(bos.toByteArray()), 1);
PdfImportedPage importPage1 = copy.getImportedPage(new PdfReader(bos.toByteArray()), 2);
PdfImportedPage importPage2 = copy.getImportedPage(new PdfReader(bos.toByteArray()), 3);
copy.addPage(importPage);
copy.addPage(importPage1);
copy.addPage(importPage2);
doc.close();
} catch (IOException e) {
System.out.println(e);
} catch (DocumentException e) {
System.out.println(e);
}
}
}
@AutoLog(value = "生成学生的校长特别奖学金pdf")
@ApiOperation(value = "生成学生的校长特别奖学金pdf", notes = "生成学生的校长特别奖学金pdf")
@GetMapping(value = "/getXZPDF")
public Result<?> getXZPDF(@RequestParam(required = true) String stId) {
System.out.println("===========start=============");
StStudent student = stStudentService.getStudentId(stId);
List<StAwards> stAwards = stAwardsService.getStStAwardsId(stId);
StScholarships stScholarships = stScholarshipsService.getStScholarshipsIds(stId);
GetStuPdf.getPdf(student, sysDictService, stClassService, stAwards, stScholarships, sysDepartService);
System.out.println("===========end=============");
Result result = new Result();
return result;
}