java图文结合制作证书

servicempl层

@Override
public AjaxResult pictureWithWord(LwCertificateInfo lwCertificateInfo) throws IOException {
    try {
        /**读取原图信息*/
        String scrImgPath = "D:\\证书信息\\培训合格证书.jpg";
        /**得到文件*/
        File srcImgFile = new File(scrImgPath);
         /**文件转化为图片*/
        Image srcImg = ImageIO.read(srcImgFile);
         /**获取图片的宽3306*/
        int srcImgWidth = srcImg.getWidth(null);
         /**获取图片的高2236*/
        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) {
        // TODO: handle exception
    }
    return AjaxResult.success();
}

service层

AjaxResult pictureWithWord(LwCertificateInfo lwCertificateInfo) throws IOException;

控制层调用

lwCertificateInfoService.pictureWithWord(lwCertificateInfo);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值