浏览代码

1.调整签章位置。

zhengqiang 5 年之前
父节点
当前提交
8a395c4599

+ 9 - 1
picc-admin-server/src/main/java/com/jpsoft/picc/modules/base/controller/AttachmentController.java

@@ -8,10 +8,12 @@ import com.jpsoft.picc.modules.base.service.CompanyMemberService;
 import com.jpsoft.picc.modules.base.service.CompanyService;
 import com.jpsoft.picc.modules.base.service.InsuranceDefinitionLimitService;
 import com.jpsoft.picc.modules.business.entity.InsuranceApplication;
+import com.jpsoft.picc.modules.business.entity.InsurancePolicy;
 import com.jpsoft.picc.modules.business.entity.InsurancePolicyMember;
 import com.jpsoft.picc.modules.business.service.ApplicationPolicyService;
 import com.jpsoft.picc.modules.business.service.InsuranceApplicationService;
 import com.jpsoft.picc.modules.business.service.InsurancePolicyMemberService;
+import com.jpsoft.picc.modules.business.service.InsurancePolicyService;
 import com.jpsoft.picc.modules.common.config.OSSConfig;
 import com.jpsoft.picc.modules.common.config.PdfConfig;
 import com.jpsoft.picc.modules.common.dto.MessageResult;
@@ -60,6 +62,9 @@ public class AttachmentController {
     @Autowired
     private InsuranceApplicationService insuranceApplicationService;
 
+    @Autowired
+    private InsurancePolicyService insurancePolicyService;
+
     @Autowired
     private InsuranceDefinitionLimitService insuranceDefinitionLimitService;
 
@@ -132,6 +137,7 @@ public class AttachmentController {
 
             Company company = companyService.get(insuranceApplication.getCompanyId());
 
+
             List<InsuranceDefinitionLimit> insuranceDefinitionLimitList = insuranceDefinitionLimitService.findByDefinitionId(insuranceApplication.getDefinitionId());
 
             List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
@@ -187,7 +193,9 @@ public class AttachmentController {
 
             log.warn("生成PDF文档:" + filePath);
 
-            ItextPDFUtil.createPdf(insuranceApplication, mapList, list, logoUrl,filePath);
+            InsurancePolicy insurancePolicy = insurancePolicyService.get(policyId);
+
+            ItextPDFUtil.createPdf(insuranceApplication,insurancePolicy, mapList, list, logoUrl,filePath);
 
             String watermarkFilePath = folderPath + File.separator + DateTime.now().toString("yyyyMMddHHmmssSSS") + "-watermark.pdf";
 

+ 7 - 15
picc-common/src/main/java/com/jpsoft/picc/modules/common/utils/ItextPDFUtil.java

@@ -5,6 +5,7 @@ import com.itextpdf.text.*;
 import com.itextpdf.text.pdf.*;
 import com.itextpdf.text.pdf.draw.LineSeparator;
 import com.jpsoft.picc.modules.business.entity.InsuranceApplication;
+import com.jpsoft.picc.modules.business.entity.InsurancePolicy;
 import com.jpsoft.picc.modules.business.entity.InsurancePolicyMember;
 
 import java.io.File;
@@ -102,8 +103,7 @@ public class ItextPDFUtil {
         stamp.close();// 关闭
     }
 
-
-    public static void createPdf(InsuranceApplication insuranceApplication, List<Map<String,Object>> mapList,List<InsurancePolicyMember> list,String logoUrl,String downloadFilePath)throws Exception{
+    public static void createPdf(InsuranceApplication insuranceApplication,InsurancePolicy insurancePolicy, List<Map<String,Object>> mapList,List<InsurancePolicyMember> list,String logoUrl,String downloadFilePath)throws Exception{
         //测试pdf保存路径
      //   String filePath = "C:/Users/Administrator/Desktop/投保单.pdf";
         File file = new File(downloadFilePath);
@@ -123,7 +123,7 @@ public class ItextPDFUtil {
         document.open();
         try{
             // 4.向文档中添加内容
-            new ItextPDFUtil().generatePDF(document,insuranceApplication,mapList,list,logoUrl);
+            new ItextPDFUtil().generatePDF(document,insuranceApplication,insurancePolicy,mapList,list,logoUrl);
         }catch (Exception ex){
             throw new Exception(ex.getMessage());
         }finally {
@@ -166,7 +166,7 @@ public class ItextPDFUtil {
 
     // 生成PDF文件
 
-    public void generatePDF(Document document,InsuranceApplication insuranceApplication, List<Map<String,Object>> mapList,List<InsurancePolicyMember> list,String logoUrl) throws Exception {
+    public void generatePDF(Document document, InsuranceApplication insuranceApplication, InsurancePolicy insurancePolicy, List<Map<String,Object>> mapList, List<InsurancePolicyMember> list, String logoUrl) throws Exception {
       //  Image image1 = Image.getInstance("C:/Users/Administrator/Desktop/picc/logo.png");
         Image image1 = Image.getInstance(logoUrl);
         Paragraph p1 = new Paragraph("", titlefont);
@@ -266,32 +266,24 @@ public class ItextPDFUtil {
             if ("累计法律诉讼费用限额".equals(mapData.get("name"))){
                 lawValue = (String)mapData.get("limit")+(String)mapData.get("unit");
             }
-
-
         }
 
-
-
         table.addCell(PdfTable.createCell("二、承保信息", textfont, Element.ALIGN_LEFT, 7,1,BaseColor.PINK, true));
-
         table.addCell(PdfTable.createCell(insuranceApplication.getDefinitionName(), textfont, Element.ALIGN_CENTER,2,mapList.size()+1,BaseColor.WHITE,false));
-
         table.addCell(PdfTable.createCell("限额名称", textfont, Element.ALIGN_CENTER,3,1,BaseColor.WHITE,false));
         table.addCell(PdfTable.createCell("责任限额/免赔额", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
         table.addCell(PdfTable.createCell("保险费(元)", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
 
-
         int n =0;
         for (Map<String,Object> mapData : mapList){
             table.addCell(PdfTable.createCell(mapData.get("name").toString(), textfont, Element.ALIGN_CENTER,3,1,BaseColor.WHITE,false));
             table.addCell(PdfTable.createCell(mapData.get("limit").toString()+mapData.get("unit"), textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
             n++;
             if (n==1){
-                table.addCell(PdfTable.createCell(String.valueOf(insuranceApplication.getInsuranceFee()), textfont, Element.ALIGN_CENTER,1,mapList.size(),BaseColor.WHITE,false));
+                table.addCell(PdfTable.createCell(String.valueOf(insurancePolicy.getInsuranceFee()), textfont, Element.ALIGN_CENTER,1,mapList.size(),BaseColor.WHITE,false));
             }
         }
 
-
 //        table.addCell(PdfTable.createCell("累计责任限额", textfont, Element.ALIGN_CENTER,3,1,BaseColor.WHITE,false));
 //        table.addCell(PdfTable.createCell(cumulativeValue, textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
 //        table.addCell(PdfTable.createCell(String.valueOf(insuranceApplication.getInsuranceFee()), textfont, Element.ALIGN_CENTER,1,6,BaseColor.WHITE,false));
@@ -326,12 +318,12 @@ public class ItextPDFUtil {
         table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
 
         table.addCell(PdfTable.createCell("保险费合计(人民币)", textfont, Element.ALIGN_CENTER,2,1,BaseColor.WHITE,false));
-        table.addCell(PdfTable.createCell("(大写):"+ Convert.digitToChinese(insuranceApplication.getInsuranceFee())+"\u3000\u3000\u3000\u3000(小写):¥ "+new DecimalFormat("#,##0.00").format(insuranceApplication.getInsuranceFee()).toString(), textfont, Element.ALIGN_LEFT,5,1,BaseColor.WHITE,false));
+        table.addCell(PdfTable.createCell("(大写):"+ Convert.digitToChinese(insurancePolicy.getInsuranceFee())+"\u3000\u3000\u3000\u3000(小写):¥ "+new DecimalFormat("#,##0.00").format(insurancePolicy.getInsuranceFee()).toString(), textfont, Element.ALIGN_LEFT,5,1,BaseColor.WHITE,false));
 
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
 
         table.addCell(PdfTable.createCell("保险期间", textfont, Element.ALIGN_CENTER,2,1,BaseColor.WHITE,false));
-        table.addCell(PdfTable.createCell("自"+simpleDateFormat.format(insuranceApplication.getStartTime())+"零时起至"+simpleDateFormat.format(insuranceApplication.getEndTime())+"二十四时止。", textfont, Element.ALIGN_CENTER,5,1,BaseColor.WHITE,false));
+        table.addCell(PdfTable.createCell("自"+simpleDateFormat.format(insurancePolicy.getStartTime())+"零时起至"+simpleDateFormat.format(insurancePolicy.getEndTime())+"二十四时止。", textfont, Element.ALIGN_CENTER,5,1,BaseColor.WHITE,false));
 
         table.addCell(PdfTable.createCell("保险合同争议处理", textfont, Element.ALIGN_CENTER,2,1,BaseColor.WHITE,false));
         table.addCell(PdfTable.createCell("□提交______________仲裁委员会仲裁  □诉讼", textfont, Element.ALIGN_LEFT,5,1,BaseColor.WHITE,false));

+ 52 - 11
picc-common/src/main/java/com/jpsoft/picc/modules/common/utils/Watermark.java

@@ -2,9 +2,14 @@ package com.jpsoft.picc.modules.common.utils;
 
 import com.itextpdf.text.*;
 import com.itextpdf.text.pdf.*;
+import com.itextpdf.text.pdf.parser.ImageRenderInfo;
+import com.itextpdf.text.pdf.parser.PdfReaderContentParser;
+import com.itextpdf.text.pdf.parser.RenderListener;
+import com.itextpdf.text.pdf.parser.TextRenderInfo;
 import lombok.extern.slf4j.Slf4j;
 
 import java.io.FileOutputStream;
+import java.util.ArrayList;
 
 /**
  * @author 墨鱼_mo
@@ -45,24 +50,60 @@ public class Watermark extends PdfPageEventHelper {
             gs1.setFillOpacity(0.8f);
 
             Image image = Image.getInstance(images);
-         //   int imgHeight = (int)image.getHeight();
-        //    int imgWidth = (int)image.getWidth();
-
             int n = reader.getNumberOfPages();
             PdfContentByte under;
 
-            under = stamper.getOverContent(2);
+            int pageNumber = 2;
+            under = stamper.getOverContent(pageNumber);
             under.setGState(gs1);
 
-            Rectangle pageRect = reader.getPageSizeWithRotation(2);
+            Rectangle pageRect = reader.getPageSizeWithRotation(pageNumber);
+
+            image.scaleToFit(pageRect.getWidth()/6,pageRect.getHeight()/6);
+
+            //读取【投保人签名 / 签章】位置
+            PdfReaderContentParser pdfReaderContentParser = new PdfReaderContentParser(reader);
+
+            String keyword = "投保人签名 / 签章";
+            int[] matchArr = new int[1];
+
+            final ArrayList<Float> posList = new ArrayList<>();
+
+            pdfReaderContentParser.processContent(pageNumber, new RenderListener() {
+                @Override
+                public void renderText(TextRenderInfo textRenderInfo) {
+                    String text = textRenderInfo.getText(); // 整页内容
 
-          //  image.setRotation(45);
-            image.scaleToFit(pageRect.getWidth()/5,pageRect.getHeight()/5);
+                    if (null != text && text.contains(keyword)) {
+                        com.itextpdf.awt.geom.Rectangle2D.Float boundingRectangle = textRenderInfo.getBaseline().getBoundingRectange();
+                        posList.add(boundingRectangle.x);
+                        posList.add(boundingRectangle.y);
+                    }
+                }
 
-            image.setAbsolutePosition(pageRect.getWidth()/2,pageRect.getHeight()/3);
-            under.addImage(image);
+                @Override
+                public void renderImage(ImageRenderInfo arg0) {
+                    // TODO Auto-generated method stub
 
+                }
 
+                @Override
+                public void endTextBlock() {
+                    // TODO Auto-generated method stub
+
+                }
+
+                @Override
+                public void beginTextBlock() {
+                    // TODO Auto-generated method stub
+
+                }
+            });
+
+            if (posList.size()>0) {
+                image.setAbsolutePosition(posList.get(0) + 100, posList.get(1));
+                under.addImage(image);
+            }
 
             for (int i = 3; i <= n; i++) {
                 // 获得PDF最顶层
@@ -74,7 +115,7 @@ public class Watermark extends PdfPageEventHelper {
                 //A4像素 842*596
                 float maxSize = 842;
              //   image.setRotation(45);
-                image.scaleToFit(pageRect.getWidth()/5,pageRect.getHeight()/5);
+                image.scaleToFit(pageRect.getWidth()/6,pageRect.getHeight()/6);
                 image.setAbsolutePosition(2*pageRect.getWidth()/3,4*pageRect.getHeight()/5);
                 under.addImage(image);
 
@@ -105,7 +146,7 @@ public class Watermark extends PdfPageEventHelper {
 
     public static void main(String[] args) {
         try {
-            Watermark.imageWatermark("C:\\Users\\Administrator\\Desktop\\投保单.pdf","C:\\Users\\Administrator\\Desktop\\test.pdf","C:\\Users\\Administrator\\Desktop\\picc\\logo2.png");
+            Watermark.imageWatermark("E:\\test.pdf","E:\\test2.pdf","C:\\picc\\logo.png");
         } catch (Exception e) {
             e.printStackTrace();
         }