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();

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.