Can we remove watermark from PDF file like attached file using Appose JAVA component.
If yes then let us know how?
Hi Raj,
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 watermark with Aspose.Pdf using deleteStampById() method but in this case watermark should be added using Aspose.Pdf API. Please check following sample code for the 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()); }
}
contentEditor.save(myDir+"Hellowrold_deletestamp.pdf");
</o:p>
<o:p> </o:p>
<o:p>Hopefully it will help you to accomplish your requirements. Please feel free to contact us for any further assistance.</o:p>
<o:p>
</o:p>
<o:p>Best Regards,</o:p>