|
@@ -45,38 +45,55 @@ public class Watermark extends PdfPageEventHelper {
|
|
|
gs1.setFillOpacity(0.25f);
|
|
|
|
|
|
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();
|
|
|
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最顶层
|
|
|
under = stamper.getOverContent(i);
|
|
|
under.setGState(gs1);
|
|
|
|
|
|
- Rectangle pageRect = reader.getPageSizeWithRotation(i);
|
|
|
+ // Rectangle pageRect1 = reader.getPageSizeWithRotation(i);
|
|
|
|
|
|
//A4像素 842*596
|
|
|
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();
|
|
|
reader.close();
|