42 PdfReader reader =
new PdfReader(src);
43 int n = reader.getNumberOfPages();
44 PdfStamper stamper =
new PdfStamper(reader, dest);
45 stamper.setRotateContents(
false);
47 PdfGState gs1 =
new PdfGState();
48 gs1.setFillOpacity(0.2f);
53 String text[] = watermark.getText();
54 Phrase p[] =
new Phrase[text.length];
55 if(watermark.hasText()) {
57 Font f =
new Font(Font.HELVETICA, 30, Font.BOLD);
58 for(
int i = 0; i < text.length; i++) {
59 p[i] =
new Phrase(text[i], f);
63 float w = 0.0F, h = 0.0F;
64 if(watermark.hasImage()) {
66 img = Image.getInstance(watermark.getImage());
67 w = img.getScaledWidth();
68 h = img.getScaledHeight();
71 for (
int i = 1; i <= n; i++) {
72 pagesize = reader.getPageSize(i);
73 x = (pagesize.getLeft() + pagesize.getRight()) / 2;
74 y = (pagesize.getTop() + pagesize.getBottom()) / 2;
75 over = stamper.getOverContent(i);
79 float yp = y + ((p.length * 40) / 2);
81 ColumnText.showTextAligned(over, Element.ALIGN_CENTER, ph, x, yp, watermark.getRotation());
86 over.addImage(img, w, 0, 0, h, x - (w / 2), y - (h / 2));