Hi Friends,
I am having a pdf which has to be watermarked.But the code below I use is writing contents of my PDF into another PDf which is being watermarked.Please suggest any ideas which helps me watermark the same pdf without creating a new one.
Please find the code below.

PdfReader Read_PDF_To_Watermark = new PdfReader(RESOURCE_DATA.getString("FILE_PATH"));
int number_of_pages = Read_PDF_To_Watermark.getNumberOfPages();
PdfStamper stamp = new PdfStamper(Read_PDF_To_Watermark, new FileOutputStream(RESOURCE_DATA.getString("FILE_PATH2")));
int i = 0;
Image watermark_image = Image.getInstance(RESOURCE_DATA.getString("LOGO"));
watermark_image.setAbsolutePosition(200, 400);
PdfContentByte add_watermark;            
while (i < number_of_pages) {
i++;
add_watermark = stamp.getUnderContent(i);
add_watermark.addImage(watermark_image);
}
stamp.close();

Edited 4 Years Ago by peter_budo: Keep It Clear - Do use code tags when posting any code

As far as I'm aware that is the approach of any PDF library that you cannot overwrite currently opened document. What you have to do is open document, make changes, save in new document, remove original and rename new one.

This question has already been answered. Start a new discussion instead.