servicempl层
@Override
public AjaxResult pictureWithWord(LwCertificateInfo lwCertificateInfo) throws IOException {
try {
String scrImgPath = "D:\\证书信息\\培训合格证书.jpg";
File srcImgFile = new File(scrImgPath);
Image srcImg = ImageIO.read(srcImgFile);
int srcImgWidth = srcImg.getWidth(null);
int srcImgHeight = srcImg.getHeight(null);
BufferedImage bufImg = new BufferedImage(srcImgWidth, srcImgHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bufImg.createGraphics();
g.drawImage(srcImg, 0, 0, srcImgWidth, srcImgHeight, null);
Color color = new Color(0, 0, 0, 255);
g.setColor(color);
Font font = new Font("微软雅黑", Font.PLAIN, 45);
g.setFont(font);
String putLaborName = lwCertificateInfo.getLaborName();
String putLaborIdcode = lwCertificateInfo.getLaborIdcode();
String putEnterpriseName = lwCertificateInfo.getEnterpriseName();
String putPostName = lwCertificateInfo.getPostName();
String putCategoryCode = lwCertificateInfo.getCategoryCode();
String putSendCategoryUnit = lwCertificateInfo.getSendCategoryUnit();
Date dateCertificateBeginDate = lwCertificateInfo.getCertificateBeginDate();
Date dateCertificateEndDate = lwCertificateInfo.getCertificateEndDate();
SimpleDateFormat Begin = new SimpleDateFormat("yyyy MM dd");
SimpleDateFormat End = new SimpleDateFormat("yyyy MM dd");
String putCertificateBeginDate = Begin.format(dateCertificateBeginDate);
String putCertificateEndDate = End.format(dateCertificateEndDate);
int x_putLaborName = 1060;
int y_putLaborName = 1055;
int x_putLaborIdcode = 1060;
int y_putLaborIdcode = 1189;
int x_EnterpriseName = 1060;
int y_EnterpriseName = 1319;
int x_putPostName = 1060;
int y_putPostName = 1447;
int x_putCategoryCode = 1060;
int y_putCategoryCode = 1575;
int x_putSendCategoryUnit = 2700;
int y_putSendCategoryUnit = 1815;
int x_putCertificateBeginDate = 1057;
int y_putCertificateBeginDate = 1705;
int x_putCertificateEndDate = 1585;
int y_putCertificateEndDate = 1705;
g.drawString(putLaborName, x_putLaborName, y_putLaborName);
g.drawString(putLaborIdcode, x_putLaborIdcode, y_putLaborIdcode);
g.drawString(putEnterpriseName, x_EnterpriseName, y_EnterpriseName);
g.drawString(putPostName, x_putPostName, y_putPostName);
g.drawString(putCategoryCode, x_putCategoryCode, y_putCategoryCode);
g.drawString(putSendCategoryUnit, x_putSendCategoryUnit, y_putSendCategoryUnit);
g.drawString(putCertificateBeginDate, x_putCertificateBeginDate, y_putCertificateBeginDate);
g.drawString(putCertificateEndDate, x_putCertificateEndDate, y_putCertificateEndDate);
g.dispose();
String tarImgPath = "D:\\证书信息\\" + lwCertificateInfo.getLaborName() + ".jpg";
FileOutputStream outImgStream = new FileOutputStream(tarImgPath);
ImageIO.write(bufImg, "jpg", outImgStream);
System.out.println("添加水印完成");
outImgStream.flush();
outImgStream.close();
String pictureWithWordUrl = pathPicture+lwCertificateInfo.getLaborName();
lwCertificateInfo.setIdPhotoUrl(pictureWithWordUrl);
} catch (IOException e) {
}
return AjaxResult.success();
}
service层
AjaxResult pictureWithWord(LwCertificateInfo lwCertificateInfo) throws IOException;
控制层调用
lwCertificateInfoService.pictureWithWord(lwCertificateInfo);