954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Watemarking in the Same PDF

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();
arathy nair
Newbie Poster
12 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

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.

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: