1.定义ftl文件模板
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>开启情况说明</title> <style> @page{size:210mm 297mm;} *{ margin: 0; padding: 0; box-sizing: border-box; color: black; font-family: SimSun; } body{ font-family: SimSun; } /*html,body{ margin:0; padding:0; color: black; font-family: SimSun; }*/ .container{ padding:0 60px; } .title{ padding-top:3px; text-align:center; } .title>h1{ font-weight:normal; } .content{ line-height: 35px; font-family: SimSun; font-size: 18px; } .content p{margin:0;} .info{ text-indent: 2em; } .date{ float: right; position: relative; } .img-sign{ width:4cm; height: 4cm; opacity: 0.75; margin-left: 20px; margin-top: -100px; } </style> </head> <body> <div class="container"> <div class="title"> <h1>开启情况说明</h1> </div> <#--<div class="content"> <p>特此说明</p> <div class="date"> <p>2020年07月09日08时32分</p> <p>(签章)</p> <img class="img-sign" src="C:\Users\tjs\Desktop\001.jpg" /> </div> </div>--> <div class="content"> <p>${purBuyName}:</p> <p>${saasFlagName!''}:</p> <p class="info">该项目于${(publishTime?string('yyyy年MM月dd日HH时mm分'))!''}。</p> <p>特此说明</p> <div class="date"> <p>${(nowTime?string('yyyy年MM月dd日HH时mm分'))!''}</p> <p>${platform!''}(签章)</p> <img class="img-sign" src=""/> </div> </div> </div> </body> </html>
2.后台数据获取
public StartHallDO setOpenFile(StartHallDO startHall, String quotationNumber) {
String id = startHall.getId();
StartHallDO startHallDO = startHallService.get(id);
startHallDO.setCause(startHall.getCause());
if (startHall.getOpenFailPdfFile() == null || "".equals(startHall.getOpenFailPdfFile())) {
Map<String, Object> creatMap = getMap(startHallDO);
String date = mkSysFile(id);
String pdfFile = CreateFileConstants.PURCHASE + date + startHallDO.getId() + "/" + creatMap.get("purName").toString() + startHallDO.getSectionCode() + "标段-开启情况说明.pdf";//创建空白pdf
String createPdfPash = commonConfig.getUploadPath() + pdfFile; //需要创建的pdf文件路径
BufferedWriter bwpdf;
try {
bwpdf = new BufferedWriter(new FileWriter(createPdfPash));
bwpdf.close();
CreatePDFUtil.createPDF(creatMap, "/ftl/pdfOpenFail.ftl", createPdfPash);
startHall.setOpenFailPdfFile("/files/" + pdfFile);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
return startHall;
}