import java.io.FileOutputStream;
import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
public class AddWatermarkImageToAnExistingPDFFile {
public static void main(String[] args) {
try {
PdfReader reader = new PdfReader("7189D0930.pdf");
int n = reader.getNumberOfPages();
PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("NewPDFWithWatermarkImage.pdf"));
int i = 0;
PdfContentByte under;
Image img = Image.getInstance("logo.png");
img.setAbsolutePosition(200, 400);
while (i < n) {
i++;
under = stamp.getUnderContent(i);
under.addImage(img);
}
stamp.close();
}
catch (Exception de) {
de.printStackTrace();
}
}
}
I've tried tracing but I don't have enough knowledge to fully understand whats going on in the Itext classes. I simply need to be able to watermark a pdf. I'm using itext since I will have to watermark 500-600 and will modify it so it can read in a notepad file of all of the names. Simply I run the program it produces the pdf but no evidence of it watermarking it is able to open the .png file but for whatever reason is not on the final pdf.