Hello, may I ask how to cancel or delete using aspose.pdf PDF watermarks, please provide relevant Demo。my email hneg_qiaoer@qq.com,
Hi there,
PdfContentEditor editor = new PdfContentEditor();<o:p></o:p>
editor.BindPdf(myDir + “watermark.pdf”);<o:p></o:p>
editor.ReplaceText(“Test Watermark”, “”);<o:p></o:p>
editor.Save(myDir + “watermark_out.pdf”);<o:p></o:p>
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 with StampId and later you can delete that specific watermark. Please check following sample code for the purpose.
//****Adding Text Stamp****//
Document pdfDocument = new Document(myDir + "Helloworld.pdf");
FormattedText txtFormatted = new FormattedText();
txtFormatted.AddNewLineText("Processed/Reviewed By:");
txtFormatted.AddNewLineText(DateTime.Now.ToString());
TextStamp textStamp = new TextStamp(txtFormatted);
textStamp.Background=true;
textStamp.BottomMargin=50;
textStamp.HorizontalAlignment=HorizontalAlignment.Right;
textStamp.VerticalAlignment=VerticalAlignment.Bottom;
textStamp.YIndent=10;
textStamp.TextState.FontSize=10;
textStamp.Opacity=100;
//Set ID of stamp
textStamp.setStampId(999);
pdfDocument.Pages[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");
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].StampId == 999)
{ contentEditor.DeleteStampById(stampInfo[i].StampId); }
}
contentEditor.Save(myDir + "Hellowrold_deletestamp.pdf");
Hopefully it will help you to accomplish your requirements. Please feel free to contact us for any further assistance.
Best Regards,