How to add an image watermark to a PDF file?

I'm using C# and iTextSharp to add a watermark to my PDF files:


Document document = new Document();
PdfReader pdfReader = new PdfReader(strFileLocation);
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(strFileLocationOut, FileMode.Create, FileAccess.Write, FileShare.None));
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(WatermarkLocation);
img.SetAbsolutePosition(100, 300);
PdfContentByte waterMark;
for (int pageIndex = 1; pageIndex  pdfReader.NumberOfPages; pageIndex++) {
    waterMark = pdfStamper.GetOverContent(pageIndex);
pdfStamper.FormFlattening = true;
It works fine, but my problem is that in some PDF files no watermark is added although the file size increased, any idea?

Posted on StackOverflow on Jul 8, 2013 by Abady

The fact that the file size increases is a good indication that the watermark is added. The main problem is that you're adding the watermark outside the visible area of the page. See my answer to the question "How to position text relative to page using iText?" In Java if you use iText 7 you need something like this (use the same methods in C#):

Rectangle pagesize = pdfDoc.getPage(pageIndex).getCropBox();
if (pagesize == null)
    pagesize = pdfDoc.getPage(pageIndex).getMediaBox();

Image img = new Image(ImageDataFactory.create(imageSrc));
img.setFixedPosition (

That is: if you want to add the image in the lower-left corner of the page. You can add an offset, but make sure the offset in the x direction doesn't exceed the width of the page, and the offset in the y direction doesn't exceed the height of the page.

Click this link if you want to see how to answer this question in iText 5.

Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now