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

Free Support Forum - aspose.com

Unable to remove stamps

Hi,

I am not sure if I am doing something wrong or what might be the issue, but it seems that I am unable to remove stamps.

EDIT: This seems to happen if I add another stamp and then try to remove all of the stamps.
2nd EDIT: I stamped the PDF first, and then tried to remove it, and it doesn’t remove it. Code is the same.
Please see these files:
OoPdfFormExample.OriginalFile.pdf (82.9 KB)
OoPdfFormExample.OriginalFile.Stamped.pdf (75.8 KB)

Attached is a zip file that has the file that I use to test, stamp output file, and then the file from where stamp is removed as well the code that I run.

PDF.Add.Remove.Stamp.Sample.zip (165.9 KB)

Here is the code what it is to remove the stamp:
///


/// Removes stamps from PDF file.
///

///
private static void RemoveStamp( string pdfFile )
{
// Create PDF content editor.
Aspose.Pdf.Facades.PdfContentEditor contentEditor = new Aspose.Pdf.Facades.PdfContentEditor();

// Open the temp file.
contentEditor.BindPdf( pdfFile );

// Process all pages.
foreach ( Page page in contentEditor.Document.Pages )
{
	// Get the stamp infos.
	Aspose.Pdf.Facades.StampInfo[] stampInfos = contentEditor.GetStamps( page.Number );

	//Process all stamp infos
	foreach ( Aspose.Pdf.Facades.StampInfo stampInfo in stampInfos )
	{
		// If this is my stamp.
		if ( stampInfo.Text == MyStampText )
		{
			// Use try catch so we can output possible error w/out break point.
			try
			{
				contentEditor.DeleteStampById( page.Number, stampInfo.StampId );
			}
			catch ( Exception e )
			{
				Console.WriteLine( e );
			}
		}
	}
}

// Save changes to the temp file.
contentEditor.Save( StampRemovedPdfFile );

}

@Matti_Ketonen

Thanks for contacting support.

The text stamp was not being removed because you were using DeleteStampById() mehtod which takes StampID to perform deletion, whereas while adding stamp, you were not assigning any ID to the stamp. The issue got resolved by using DeleteStamp() method which takes page number and stamp index as arguments. Please check following code snippet and attached output, generated by below code, for your reference.

 // Create PDF content editor.
 Facades.PdfContentEditor contentEditor = new Facades.PdfContentEditor();
 // Open the temp file.
 contentEditor.BindPdf(dataDir + "OoPdfFormExample.Original_StampedOut.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 + "OoPdfFormExample.Original_StampRemoved.pdf");

OoPdfFormExample.Original_StampRemoved.pdf (75.5 KB)

Furthermore, if you uncomment setStampId() method from your existing code snippet, the code will also generate correct results and in case you want to add more than one stamps with IDs, you can add each of them with different ones, so that they can be deleted by DeleteStampById() method later.

In case of any further assistance, please feel free to contact us.


Best Regards,
Asad Ali

Thanks!

That solved that issue. However the related issue that I trying to work around still persists.

After removing stamp, it will break the PDF somehow.

Remove stamp from this, the stamp is in the lower left corner.
OoPdfFormExample.Original.WithStamp.SavedFromAdobeReader.pdf (72.5 KB)

And saved to:
OoPdfFormExample.Original.WithStamp.SavedFromAdobeReader.Stamp.Removed.pdf (71.5 KB)

@Matti_Ketonen

Thanks for contacting support and sharing more details.

I have also observed the same issue which you have mentioned. After removing the TextStamps from the document, it got corrupted. However, I have logged an issue as PDFNET-43041 in our issue tracking system. We will further look into the details of the issue and keep you posted on the status of its resolution. Please be patient and spare us little time.

We are sorry for the inconvenience.


Best Regards,
Asad Ali