This is essentially identical to adding a header or footer.
You need to create a class that implements PdfPageEvent , and in OnPageEnd , grab the PdfContentByte page and draw an image. Use absolute position.
Note. You probably want to extract from PdfPageEventHelper, it has empty implementations of all the page events, so you just need to write the method that you really need.
Note. If your image is mostly transparent, drawing it on top of your page will cover many things. IIRC ("If I Return Right"), PNG and GIF files added by iText will automatically be masked appropriately, allowing things to display beneath them.
If you want to add an opaque image to everything, you should replace OnStartPage() instead.
This is Java, but conversion is basically a matter of using the method name and exchanging get / set calls to access the properties.
Image watermarkImage = new Image(imgPath); watermarkImage.setAbsolutePosition(x, y); writer.setPageEvent( new MyPageEvent(watermarkImage) ); public MyPageEvent extends PdfPageEventHelper { private Image waterMark; public MyPageEvent(Image img) { waterMark = img; } public void OnEndPage(PdfWriter writer, Document doc) { PdfContentByte content = writer.getContent(); content.addImage( waterMark ); } }
source share