Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using iTextPDF to add semi transparent watermarks?

919944Mar 6 2012 — edited Mar 9 2012
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 6 2012
Added on Mar 6 2012
6 comments
2,259 views