Can we remove watermark from PDF file like attached file using Appose JAVA component.
If yes then let us know how?
Hi Raj,
Thanks for your inquiry. You can remove TextStamp/Watermark by replacing stamp contents with an empty text string as follows:
PdfContentEditor editor = new PdfContentEditor();
editor.bindPdf(myDir + "watermark.pdf");
editor.replaceText("Neevia Document Converter Pro v6.5", " );
editor.save(myDir + "watermark_out.pdf");
Moreover, there is another convenient way to delete a watermark using Aspose.Pdf with the deleteStampById() method, but in this case, the watermark should be added using Aspose.Pdf API. Please check the following sample code for this purpose:
//****Adding Text Stamp****//
Document pdfDocument=new Document(myDir+"Helloworld.pdf");
Date dtest = new Date();
com.aspose.pdf.facades.FormattedText txtFormatted = new com.aspose.pdf.facades.FormattedText();
txtFormatted.addNewLineText("Processed/Reviewed By:");
txtFormatted.addNewLineText(dtest.toString());
TextStamp textStamp = new TextStamp(txtFormatted);
textStamp.setBackground(true);
textStamp.setBottomMargin(50);
textStamp.setHorizontalAlignment(HorizontalAlignment.Right);
textStamp.setVerticalAlignment(VerticalAlignment.Bottom);
textStamp.setYIndent(10);
textStamp.getTextState().setFontSize(10.0F);
textStamp.setOpacity(100);
//Set ID of stamp
textStamp.setStampId(999);
pdfDocument.getPages().get_Item(1).addStamp(textStamp);
//save output document
pdfDocument.save(myDir+"Helloworld_textstamp.pdf");
//Removing Text Stamp//
PdfContentEditor contentEditor = new PdfContentEditor();
contentEditor.bindPdf(myDir + “Helloworld_textstamp.pdf”);
com.aspose.pdf.facades.StampInfo[] stampInfo = contentEditor.getStamps(1);
//Loop through each stamp
for (int i = 0; i < stampInfo.length; i++){
//Check to see if the ID = 999, if so delete the stamp.
if (stampInfo[i].getStampId() == 999){
contentEditor.deleteStampById(stampInfo[i].getStampId());
}}
// save the updated document
contentEditor.save(myDir + “Hellowrold_deletestamp.pdf”);
Hopefully, this will help you accomplish your requirements. Please feel free to contact us for any further assistance.
Best Regards,