• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

PDF 认证评级报告位移

程序人生 supingemail 1061次浏览 0个评论

.

如图是我的信用 , 在页面上的展示

PDF 认证评级报告位移

要生成报告,因为html在处理上失真了,所以只能是按照图片进行位移了。

PDF 认证评级报告位移  图一        PDF 认证评级报告位移图二 

利用这两张图的位移来实现如上图的展示.

结果如图所示:
PDF 认证评级报告位移图三

具体实现:计算出图一的图片的长度,根据评级的CR1….CR7 的位置,计算出位移大小,把图二的红标移动到对应的位移上,就形成了图三的图。具体代码如下,可以做参照,

/**
 * 获得CR 的报告信息
 * @param crResult
 * @param pdfPropsConfig
 * @param reportType
 * @param creditCode
 * @return
 */
public static String getImage(CRResult crResult,PdfPropsConfig pdfPropsConfig,String reportType, String creditCode){
   String AAstr = crResult.getAA();
   String creditgrade = crResult.getCrLevel();
   if(StringUtils.isNotBlank(creditgrade)){
      Double grade = Double.parseDouble(AAstr);
      int point=getPointx(grade,creditgrade);
      try {
         String srcPath = pdfPropsConfig.getImgUrl()+CommonUtils.getSplit() + "cr_img.png";
         String pointimg = pdfPropsConfig.getImgUrl()+CommonUtils.getSplit()+ "crpoint_img.png";
         // 上传文件路径
         String destFile=pdfPropsConfig.getDataPath()+CommonUtils.getSplit()+reportType+CommonUtils.getSplit()+creditCode+CommonUtils.getSplit();
         String fileName = creditCode + ".png" ;
         destFile = destFile + fileName;
         File df=new File(destFile);
         if (!df.getParentFile().exists()){
            df.getParentFile().mkdirs();
         }if (!df.exists()){
            df.createNewFile();
         }
         convertImageAddPoint(srcPath,pointimg,destFile,point);
         return destFile;
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
   return null;
}


/**
 * 分数和信用等级瞄点.
 * @param grade
 * @param creditgrade:cr1,cr2,cr3,cr4,cr5,cr6,cr7
 * @return
 */
private static int getPointx(Double grade,String creditgrade){
   int cr1xlenth=4;
   int cr2xlenth=24;
   int cr3xlenth=49;
   int cr4xlenth=100;
   int cr5xlenth=55;
   int cr6xlenth=13;
   int cr7xlenth=28;
   int x=0;
   if(grade!=null && StringUtils.isNotBlank(creditgrade)){
      if(StringUtils.equals(creditgrade,"CR1")){
         x=cr1xlenth;
      }else if(StringUtils.equals(creditgrade,"CR2")){
         x=cr2xlenth+cr1xlenth;
      }else if(StringUtils.equals(creditgrade,"CR3")){
         x=cr3xlenth+cr1xlenth+cr2xlenth;
      }else if(StringUtils.equals(creditgrade,"CR4")){
         x=cr4xlenth+cr1xlenth+cr2xlenth+cr3xlenth;
      }else if(StringUtils.equals(creditgrade,"CR5")){
         x=cr5xlenth+cr1xlenth+cr2xlenth+cr3xlenth+cr4xlenth;
      }else if(StringUtils.equals(creditgrade,"CR6")){
         x=cr6xlenth+cr1xlenth+cr2xlenth+cr3xlenth+cr4xlenth+cr5xlenth;
      }else if(StringUtils.equals(creditgrade,"CR7")){
         x=cr7xlenth+cr1xlenth+cr2xlenth+cr3xlenth+cr4xlenth+cr5xlenth+cr6xlenth;
      }
      x=x-36+7;
   }
   return x;
}

/**
 * 处理图片,将pointimg固定原图片上,并生产新的图片
 * @param srcPath
 * @param pointimg
 * @param destFile
 */
public static void convertImageAddPoint(String srcPath,String pointimg,String destFile,int x){
   try {
      BufferedImage big = ImageIO.read(new File(srcPath));
      Graphics2D gd = big.createGraphics();
      gd.setBackground(Color.white);
      BufferedImage small = ImageIO.read(new File(pointimg));
      int y = 2;
      gd.drawImage(small, x, y, small.getWidth(), small.getHeight(), null);
      //在图形和图像中实现混合和透明效果
      gd.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP,1));
      gd.dispose();
      ImageIO.write(big, "png", new File(destFile));
   } catch (Exception e) {
      e.printStackTrace();
   }
}

如此操作完成之后,就可以实现图三的效果。

 


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明PDF 认证评级报告位移
喜欢 (0)

您必须 登录 才能发表评论!

加载中……