用jasper模板生成PDF

public String renewalPdf(PolicyInformationDO policyInfo, String totalPremium, String renewalDate,String path, HttpServletRequest request,HttpServletResponse response,String type) {
      try {
         Policy pdo = policyInfo.getPolicy();
         PolicyHolder holderDO = policyInfo.getPolicyHolder();
         List<PolicyInsured> insuredList = policyInfo.getPolicyInsuredlist();
         String policyNo = pdo.getPolicyNo();
         String insurNames = "";
           for (int i = 1; i < insuredList.size(); i++) {
              insurNames = insurNames + insuredList.get(i).getName() + " ";
         }
           String planname = "";
           String planCode = pdo.getPlanCode();
          
           if("YALJYSA".equals(planCode) || "YABJLJYSA".equals(planCode) || "0261000217".equals(planCode) || "0231000516".equals(planCode)
               || "YALJYSSHXBA".equals(planCode) || "YALJYSBJXBA".equals(planCode) || "0261000217XB".equals(planCode) || "0231000516XB".equals(planCode) ){
                 planname = "计划一住院";
              }else if("YALJYSC".equals(planCode) || "YABJLJYSC".equals(planCode) || "0261000218".equals(planCode) || "0231000517".equals(planCode)
                 || "YALJYSSHXBB".equals(planCode) || "YALJYSBJXBC".equals(planCode) || "0261000218XB".equals(planCode) || "0231000517XB".equals(planCode) ){
                 planname = "计划一住院+门诊";
              }else if("YALJYSB".equals(planCode) || "YABJLJYSB".equals(planCode) || "0261000219".equals(planCode) || "0231000518".equals(planCode) 
                 || "YALJYSSHXBC".equals(planCode) || "YALJYSBJXBB".equals(planCode) || "0261000219XB".equals(planCode) || "0231000518XB".equals(planCode)){
                 planname = "计划二住院";
              }else if("YALJYSD".equals(planCode) || "YABJLJYSD".equals(planCode) || "0261000220".equals(planCode) || "0231000519".equals(planCode) 
                 || "YALJYSSHXBD".equals(planCode) || "YALJYSBJXBD".equals(planCode) || "0261000220XB".equals(planCode) || "0231000519XB".equals(planCode) ){
                 planname = "计划二住院+门诊";
              }else if("YALJYSE".equals(planCode) || "YABJLJYSE".equals(planCode) || "0261000221".equals(planCode) || "0231000520".equals(planCode) 
                 || "YALJYSSHXBE".equals(planCode) || "YALJYSBJXBE".equals(planCode) || "0261000221XB".equals(planCode) || "0231000520XB".equals(planCode)){
                 planname = "计划三住院";
              }
           
         BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",
               BaseFont.NOT_EMBEDDED);
         Font FontChinese = new Font(bf, 10, Font.NORMAL);
         String pdfUrl="pdfjasper/tongzhi.jasper";
         
         ClassPathResource pubKeyResource = new ClassPathResource(pdfUrl);
         JasperReport jasperReport = (JasperReport) JRLoader
               .loadObjectFromFile(pubKeyResource.getFile().toString());
         Map<String, Object> parameters = new HashMap<String, Object>();
         // ****设置头参数
         parameters.put("policyNo", policyNo);
         parameters.put("holderName", holderDO.getName());
         parameters.put("mainInsuredName", insuredList.get(0).getName());
         parameters.put("insureds", insurNames);
         parameters.put("plans", "定制"+planname+",住院责任(详见附表)");
         parameters.put("renewalPrieum", totalPremium);
         parameters.put("renewalDate", renewalDate);
         response.setContentType("application/msword");
         response.addHeader("Content-Disposition", "attachment; filename=\"renewal00001.pdf\"");
         JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource());
         if(!"".equals(path)){
            String tmpfilePath ="/datavg/apache-tomcat-6.0.44/webapps/examples/renewal/";
            //String tmpfilePath = request.getSession().getServletContext().getRealPath("/")+"pdf"+File.separator+"yongan"+File.separator;
            /*if(type.equals("preview")){ //浏览
               tmpfilePath=path;
            }*/
            System.out.println("===========================文件生成路径tmpfilePath="+tmpfilePath);
            File localFile = new File(tmpfilePath);   
            if(!localFile.exists()){
               System.out.println("创建文件");
               localFile.mkdir();
            }
            JasperExportManager.exportReportToPdfFile(jasperPrint, tmpfilePath + "renewal00001.pdf");
//          JasperExportManager.exportReportToPdfStream(jasperPrint, new FileOutputStream(new File("/datavg/renewal00001.pdf")));
         }else {
            // 导出为PDF
            JRPdfExporter exporter = new JRPdfExporter();
            exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
            exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,
                  response.getOutputStream());
            exporter.exportReport();// 导出
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
      System.out.println("====================================23412341234");
      return null;
   }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值