Hello there,
I am able to use the following code to add a watermark to a PDF file:
public class WaterMark {
public static void main(String[] args) throws IOException, DocumentException {
String pdfFileIn = "hello.pdf";
String pdfFileOut = "hello_watermarked.pdf";
PdfReader reader = new PdfReader(pdfFileIn);
int numberOfPages = reader.getNumberOfPages();
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(pdfFileOut));
Image watermarkImage = Image.getInstance("watermark.jpg");
watermarkImage.setAbsolutePosition(200, 400);
PdfContentByte contentByte;
int i = 0;
while (i < numberOfPages) {
i++;
contentByte = stamper.getOverContent(i);
contentByte.addImage(watermarkImage);
}
stamper.close();
}
}
However the watermark is embedded as it is, hiding the real content. However I want the watermark to be semi-transparent or something like.
Any suggestions?
Thanks.