We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to remove stamps,image stamp and rotated text?

Hi, Support:

Is there any method to remove stamps,image stamp and rotated text in pdf?
I try aspose.pdf.dll version20.7, but all failed.
How to work it out?
Input.zip (147.3 KB)
Output.zip (97.7 KB)

Please refer to the sample pdf files;
recover it.

@ducaisoft

You can use following code snippet in order to delete stamps from PDF.

// Create PDF content editor.
Facades.PdfContentEditor contentEditor = new Facades.PdfContentEditor();
// Open the temp file.
contentEditor.BindPdf(dataDir + "WithStamp.SavedFromAdobeReader.pdf");
// Process all pages.
foreach (Page page in contentEditor.Document.Pages)
{
  // Get the stamp infos.
  Facades.StampInfo[] stampInfos = contentEditor.GetStamps(page.Number);

  // Process all stamp infos
  foreach (Facades.StampInfo stampInfo in stampInfos)
  {
   try
   {
    contentEditor.DeleteStamp(page.Number, new int[] { stampInfo.IndexOnPage });//.DeleteStampById(stampInfo.StampId);
   }
   catch (Exception e)
   {
    Console.WriteLine(e);
   }
  }
}

// Save changes to a file.
contentEditor.Save(dataDir + "Stamp.Removed2.pdf");

We tried to test the scenario using your files but we could not extract them because the archives were damaged. Please share your valid files with us in case you are unable to achieve your requirements with provided code snippet.

please refer to this sample files:
Input.zip (147.3 KB)
Output.zip (97.7 KB)

When downloaded the sample files, its file extension ‘zip’ must be changed to ‘pdf’ to recover the file.

I try the code snippet, but still fail, it can not detect any stamps existing in the pdf file.

@ducaisoft

We tried using following code snippet in order to remove desired content from your PDF document but we did not get much success.

Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + @"input.pdf");
foreach (var page in doc.Pages)
{
 foreach (var annotation in page.Annotations)
 {
  page.Annotations.Delete(annotation);
 }
 foreach (Artifact artifact in page.Artifacts)
 {
  page.Artifacts.Delete(artifact);
 }
}
doc.Save(dataDir + "output207.pdf");

We also tried using doc.Pages[1].Resources.Images.Delete(1); but it did not help. Therefore, we have logged an issue as PDFNET-48580 in our issue tracking system. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.