Ver Fonte

水印添加位置调整

M墨鱼—_mo há 5 anos atrás
pai
commit
e66c596b5f

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

@@ -169,7 +169,7 @@ public class ItextPDFUtil {
     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, 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("C:/Users/Administrator/Desktop/picc/logo.png");
         Image image1 = Image.getInstance(logoUrl);
         Image image1 = Image.getInstance(logoUrl);
-        Paragraph p1 = new Paragraph("00000000000001", titlefont);
+        Paragraph p1 = new Paragraph("", titlefont);
         //设置文字居中 0靠左   1,居中     2,靠右
         //设置文字居中 0靠左   1,居中     2,靠右
         p1.setAlignment(2);
         p1.setAlignment(2);
         //设置左缩进
         //设置左缩进

+ 38 - 21
picc-common/src/main/java/com/jpsoft/picc/modules/common/utils/Watermark.java

@@ -45,38 +45,55 @@ public class Watermark extends PdfPageEventHelper {
             gs1.setFillOpacity(0.25f);
             gs1.setFillOpacity(0.25f);
 
 
             Image image = Image.getInstance(images);
             Image image = Image.getInstance(images);
-            int imgHeight = (int)image.getHeight();
-            int imgWidth = (int)image.getWidth();
+         //   int imgHeight = (int)image.getHeight();
+        //    int imgWidth = (int)image.getWidth();
 
 
             int n = reader.getNumberOfPages();
             int n = reader.getNumberOfPages();
             PdfContentByte under;
             PdfContentByte under;
 
 
-            for (int i = 1; i <= n; i++) {
+            under = stamper.getOverContent(2);
+            under.setGState(gs1);
+
+            Rectangle pageRect = reader.getPageSizeWithRotation(2);
+
+          //  image.setRotation(45);
+            image.scaleToFit(pageRect.getWidth()/5,pageRect.getHeight()/5);
+
+            image.setAbsolutePosition(pageRect.getWidth()/2,pageRect.getHeight()/5);
+            under.addImage(image);
+
+
+
+            for (int i = 4; i <= n; i++) {
                 // 获得PDF最顶层
                 // 获得PDF最顶层
                 under = stamper.getOverContent(i);
                 under = stamper.getOverContent(i);
                 under.setGState(gs1);
                 under.setGState(gs1);
 
 
-                Rectangle pageRect = reader.getPageSizeWithRotation(i);
+           //     Rectangle pageRect1 = reader.getPageSizeWithRotation(i);
 
 
                 //A4像素 842*596
                 //A4像素 842*596
                 float maxSize = 842;
                 float maxSize = 842;
-
-                for (int y = 0; y < Math.min(pageRect.getHeight(), maxSize); y += imgHeight)
-                {
-                    for (int x = 0; x < Math.min(pageRect.getWidth(), maxSize); x += imgWidth)
-                    {
-                        // 水印文字成45度角倾斜
-//                        image.setRotation(30);// 旋转 弧度
-                        // 设置旋转角度
-//                        image.setRotationDegrees(-45);// 旋转 角度
-                        // 设置等比缩放
-//                        under.setColorFill(BaseColor.GRAY);
-//                        image.scaleToFit(80,120);
-                        image.setRotation(45);
-                        image.setAbsolutePosition(x, y);
-                        under.addImage(image);
-                    }
-                }
+             //   image.setRotation(45);
+                image.scaleToFit(pageRect.getWidth()/5,pageRect.getHeight()/5);
+                image.setAbsolutePosition(2*pageRect.getWidth()/3,4*pageRect.getHeight()/5);
+                under.addImage(image);
+
+//                for (int y = 0; y < Math.min(pageRect.getHeight(), maxSize); y += imgHeight)
+//                {
+//                    for (int x = 0; x < Math.min(pageRect.getWidth(), maxSize); x += imgWidth)
+//                    {
+//                        // 水印文字成45度角倾斜
+////                        image.setRotation(30);// 旋转 弧度
+//                        // 设置旋转角度
+////                        image.setRotationDegrees(-45);// 旋转 角度
+//                        // 设置等比缩放
+////                        under.setColorFill(BaseColor.GRAY);
+////                        image.scaleToFit(80,120);
+//                        image.setRotation(45);
+//                        image.setAbsolutePosition(x, y);
+//                        under.addImage(image);
+//                    }
+//                }
             }
             }
             stamper.close();
             stamper.close();
             reader.close();
             reader.close();