Add a watermark to the same PDF in Java using Aspose.PDF

Hi,

I am trying to add a watermark to a PDF file, The example given shows how to do this but it create another PDF (outFile),

fileStamp = new PdfFileStamp(inFile, outFile);
Stamp watermarkStamp = new Stamp();
watermarkStamp.bindImage(path + “Logo.gif”);
watermarkStamp.setOrigin(100, 50);
fileStamp.addStamp(watermarkStamp);
fileStamp.close()
Rather than creating a copy (outFile), how do i append the watermark to the same file (inFile).

I am testing with Aspose.Pdf for Java 4.1.2

Thank you.



Hi Abhiruka,


Thanks for using our products.

In order to fulfill your requirement, you need to save the output in save PDF file. Please try using the following code snippet to accomplish this requirement.

In case you encounter any issue, please share the source PDF file so that we can test the scenario at our end.

[Java]

// open the PDF file and specify same
file as resultant document
<o:p></o:p>

com.aspose.pdf.facades.PdfFileStamp fileStamp = new com.aspose.pdf.facades.PdfFileStamp("c:/pdftest/35528.pdf", "c:/pdftest/35528.pdf");

// create stamp object

com.aspose.pdf.facades.Stamp watermarkStamp = new com.aspose.pdf.facades.Stamp();

watermarkStamp.bindImage("c:/pdftest/test (1).png");

watermarkStamp.setOrigin(100, 50);

fileStamp.addStamp(watermarkStamp);

fileStamp.close();

Hi Nayyer,


Thank you for the reply, I have tried the method of giving the same input and output file for PdfFileStamp. This method works for simple PDF documents which only have text but when given complex ones with images the PDF is corrupted and the original images are lost the resultant file cannot be opened as well, when trying to open the file the PDF reader shows an alert saying "Insufficient data for an image". I have attached a sample of a PDF as you requested.


Regards,
Abhiruka.

Hi Abhiruka,


I
have tested the scenario and I am able to reproduce the same problem. For the
sake of correction, I have logged it in our issue tracking system as PDFNEWJAVA-33624. We
will investigate this issue in details and will keep you updated on the status
of a correction. <o:p></o:p>

We apologize for your inconvenience.

The issues you have found earlier (filed as PDFNEWJAVA-33624) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.