java查詢資訊生成相關證書圖片
阿新 • • 發佈:2020-12-27
查詢資訊生成證書圖片
@RequestMapping(value = "/fa/applet/certificate", method = RequestMethod.GET)
public void imgReferer(HttpServletRequest request, HttpServletResponse response) {
// 將影象輸出到Servlet輸出流中。
ServletOutputStream sos = null;
try {
PageData pd = this.getPageData();
sos = response.getOutputStream();
HtmlImgGenerator imageGenerator = new HtmlImgGenerator();
imageGenerator.setSize(new Dimension(800, 1127));
// String url = new File("F:/test.html").toURI().toString();
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
System.out.println(basePath);
imageGenerator.loadUrl(basePath+"f/certificate?id="+pd. get("id"));
Thread.sleep(1000);
BufferedImage image = imageGenerator.getBufferedImage();
BufferedImage bufferedImageToWrite = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
bufferedImageToWrite.createGraphics().drawImage(image, 0, 0, Color.WHITE, null);
ImageIO.write(bufferedImageToWrite, "png", sos);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 證書頁面
*
* @return
*/
@RequestMapping(value = "/f/certificate")
public ModelAndView certificate() {
ModelAndView mv = this.getModelAndView();
PageData pd = this.getPageData();
PageData data=tDonationDetailsService.getDonationInfo(pd);
StringBuffer content=new StringBuffer();
content.append("感謝您“");
content.append(data.getString("title"));
content.append("”xxx");
data.put("content",content.toString());
data.put("time",DateUtil.getDays1());
mv.addObject("pd",data);
mv.setViewName("certificate");
return mv;
}
jsp頁面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ page session="false"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div style="padding:15px 20px 15px 15px;width: 620px;background-color: #e35f00">
<div style="padding:10px 10px 0 10px;background-color: white;border-radius: 25px 25px 0 0; ">
<div style="padding:10px 10px 0 10px;border:1px dashed red;border-radius: 25px 25px 0 0; ">
<div style="border:1px dashed red;border-radius: 25px 25px 0 0;">
<div style="padding-left: 50px;padding-right: 50px;">
<div style="text-align: center;padding-top: 50px;font-size: 70px;color:#e35f00;font-weight: bold ">xx證書</div>
<div style="text-align: center;padding-top: 10px;font-size:20px; ">編號:${pd.certificate_no}</div>
<div style="text-align: center;padding-top: 50px;padding-bottom: 20px;font-size: 36px; ">${pd.nickName}</div>
<hr style="border: 1px dashed #e35f00;"></hr>
<div style="min-height:250px;text-indent: 50px;font-size: 27px;letter-spacing: 2px;line-height: 50px;padding-top: 20px">
${pd.content}
</div>
</div>
<div style="height:200px;padding-left: 50px;padding-right: 50px;text-align: center;background: url(assets/img/zhang.png) no-repeat center center;">
<div style="text-align: center;padding-top: 50px;font-size: 27px; ">濱州市慈善總會</div>
<div style="text-align: center;padding-top: 10px;font-size: 27px; ">${pd.time}</div>
<!-- <img src="zhang.png" style="margin-top: -161px">-->
</div>
</div>
</div>
</div>
<div style="height: 150px;">
</div>
</div>
</body>
</html>