Ver Fonte

Merge remote-tracking branch 'origin/master'

zhengqiang há 5 anos atrás
pai
commit
ed5bda32e3

+ 4 - 3
picc-common/src/main/java/com/jpsoft/picc/modules/common/utils/ItextPDFUtil.java

@@ -105,7 +105,7 @@ public class ItextPDFUtil {
 
     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";
+    //    String filePath = "C:/Users/Administrator/Desktop/投保单.pdf";
         File file = new File(downloadFilePath);
 
         //创建文件
@@ -197,7 +197,7 @@ public class ItextPDFUtil {
         p3.setSpacingAfter(10f);
 
         //表格
-        PdfPTable table = PdfTable.createTable(new float[]{20, 65, 60, 70, 60, 65,120});
+        PdfPTable table = PdfTable.createTable(new float[]{20, 65, 60, 80, 70, 55,110});
         table.addCell(PdfTable.createCell("一、投保人、被保险人信息", textfont, Element.ALIGN_LEFT, 7,1,BaseColor.PINK, true));
         table.addCell(PdfTable.createCell("投保人名称", textfont, Element.ALIGN_CENTER,2,1,BaseColor.WHITE,false));
         table.addCell(PdfTable.createCell(insuranceApplication.getInsuredName(), textfont, Element.ALIGN_CENTER,3,1,BaseColor.WHITE,false));
@@ -281,6 +281,7 @@ public class ItextPDFUtil {
             n++;
             if (n==1){
                 table.addCell(PdfTable.createCell(String.valueOf(insurancePolicy.getInsuranceFee()), textfont, Element.ALIGN_CENTER,1,mapList.size(),BaseColor.WHITE,false));
+
             }
         }
 
@@ -341,7 +342,7 @@ public class ItextPDFUtil {
         table.addCell(PdfTable.createCell("投保人声明", keyfont, Element.ALIGN_CENTER, 2,2,BaseColor.WHITE, true));
         table.addCell(PdfTable.createCell("\u3000\u3000保险人已向本人提供并详细介绍了中国人民财产保险雇主责任保险条款(2015版),并对其中免除保险人责任的条款(包括但不限于责任免除、投保人被保险人义务、赔偿处理、其他事项等),以及本保险合同中付费约定和特别约定的内容向本人做了明确说明,本人已充分理解并接受上述内容,同意以此作为订立保险合同的依据,自愿投保本保险。\n" +
                 "\u3000\u3000本人授权贵公司可以从第三方就有关保险服务事宜查询、收集与本人相关的信息。本人同意贵公司将本人提供的信息、本人接受贵公司保险服务产生的信息以及贵公司从第三方查询、收集的信息(包括本单证签署之前提供、查询收集和产生的),用于人保集团及其因服务必要而委托的第三方,向本人提供服务、推介产品、开展市场调查与信息数据分析。人保集团及其委托的第三方对上述个人信息依法承担保密和信息安全义务。本条中贵公司是指中国人民财产保险股份有限公司,“人保集团”是指中国人民保险集团股份有限公司及其作为控股股东、实际控制人的公司。本授权自本单证签署时生效,具有独立法律效力,不受合同成立与否及效力状态变化的影响。如取消或变更授权,请携带有效证件在办理业务的我公司营业网点办理。\n" +
-                "\u3000\u3000上述所填写的内容均属实。", keyfont, Element.ALIGN_LEFT, new float[]{0,1,0,0},new float[]{5,5},5,1,BaseColor.WHITE,false));
+                "\u3000\u3000上述所填写的内容均属实。", keyfont, Element.ALIGN_LEFT, new float[]{0,1,1,0},new float[]{5,5},5,1,BaseColor.WHITE,false));
         table.addCell(PdfTable.createCell("投保人签名 / 签章:\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000_________年____月____日", textfont, Element.ALIGN_RIGHT, new float[]{0,1,0,1},new float[]{50,5},5,1,BaseColor.WHITE, false));
 
 

+ 64 - 6
picc-common/src/main/java/com/jpsoft/picc/modules/common/utils/Watermark.java

@@ -47,7 +47,7 @@ public class Watermark extends PdfPageEventHelper {
             PdfReader reader = new PdfReader(inputPath);
             PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputPath));
             PdfGState gs1 = new PdfGState();
-            gs1.setFillOpacity(0.8f);
+            gs1.setFillOpacity(0.5f);
 
             Image image = Image.getInstance(imageUrl);
 
@@ -56,13 +56,19 @@ public class Watermark extends PdfPageEventHelper {
             //image.setTransparency(new int[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF});
 
             int n = reader.getNumberOfPages();
-            PdfContentByte under;
+            PdfContentByte under = null;
+            Rectangle pageRect = null;
+            int pageNumber = 0;
+            final ArrayList<Float> posList = new ArrayList<>();
+
+            for (int m = 2;m<5;m++){
+                 pageNumber = m;
+
 
-            int pageNumber = 2;
             under = stamper.getOverContent(pageNumber);
             under.setGState(gs1);
 
-            Rectangle pageRect = reader.getPageSizeWithRotation(pageNumber);
+             pageRect = reader.getPageSizeWithRotation(pageNumber);
 
             image.scaleToFit(pageRect.getWidth()/6,pageRect.getHeight()/6);
 
@@ -71,7 +77,6 @@ public class Watermark extends PdfPageEventHelper {
 
             String keyword = "投保人签名 / 签章";
 
-            final ArrayList<Float> posList = new ArrayList<>();
 
             pdfReaderContentParser.processContent(pageNumber, new RenderListener() {
                 @Override
@@ -82,6 +87,7 @@ public class Watermark extends PdfPageEventHelper {
                         com.itextpdf.awt.geom.Rectangle2D.Float boundingRectangle = textRenderInfo.getBaseline().getBoundingRectange();
                         posList.add(boundingRectangle.x);
                         posList.add(boundingRectangle.y);
+
                     }
                 }
 
@@ -103,13 +109,65 @@ public class Watermark extends PdfPageEventHelper {
 
                 }
             });
+            if (posList.size()>0){
+                break;
+            }else {
+                continue;
+            }
+
+            }
 
             if (posList.size()>0) {
                 image.setAbsolutePosition(posList.get(0) + 100, posList.get(1));
                 under.addImage(image);
             }
 
-            for (int i = 3; i <= n; i++) {
+            int personListNumber = 0;
+            final ArrayList<Integer> personList = new ArrayList<>();
+            for (int l=pageNumber+1;l<10;l++){
+                personListNumber = l;
+                //读取【投保人签名 / 签章】位置
+                PdfReaderContentParser pdfReaderContentParser = new PdfReaderContentParser(reader);
+
+                String keyword = "投保单号:____________________";
+
+                pdfReaderContentParser.processContent(personListNumber, new RenderListener() {
+                    @Override
+                    public void renderText(TextRenderInfo textRenderInfo) {
+                        String text = textRenderInfo.getText(); // 整页内容
+
+                        if (null != text && text.contains(keyword)) {
+                            personList.add(1);
+                        }
+                    }
+
+                    @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 (personList.size()>0){
+                    break;
+                }else {
+                    continue;
+                }
+
+            }
+
+            for (int i = personListNumber; i <= n; i++) {
                 // 获得PDF最顶层
                 under = stamper.getOverContent(i);
                 under.setGState(gs1);