I have been investigating a case where we stamp PDFs using Aspose.Pdf library.
It seems that this is limited to PDFs that are forms or fields that can be filled.
Adding stamp works fine, and removing stamp works fine, but when the PDF has a stamp added with Aspose.Pdf methods, and then using Save As… feature from Adobe Acrobat to save the filled form… this is where things get weird.
Now trying to remove stamps, in order to add new version stamp, from this newly saved PDF file it will throw an error:
System.NullReferenceException: Object reference not set to an instance of an object.
at Aspose.Pdf.Facades.PdfContentEditor.(Matrix , OperatorCollection , Resources , List`1, Object )
at Aspose.Pdf.Facades.PdfContentEditor.(Int32 )
at Aspose.Pdf.Facades.PdfContentEditor.DeleteStampById(Int32 pageNumber, Int32 stampId)
at Aspose.Pdf.Facades.PdfContentEditor.DeleteStampById(Int32 stampId)
When saving a file from Foxit reader it works fine, so it seems that this Adobe Acrobat does something to the PDF file.
That’s the prologue for the issue…
Here is the C# method that I use to remove the stamp(s)
/// Removes stamps from PDF file.
public static void RemoveStamp( string pdfFile )
// Create PDF content editor.
PdfContentEditor contentEditor = new PdfContentEditor();
// Open the temp file.
contentEditor.BindPdf( pdfFile );
// Process all pages.
foreach ( Page page in contentEditor.Document.Pages )
// Get the stamp infos.
StampInfo stampInfos = contentEditor.GetStamps( page.Number );
// Process all stamp infos
foreach ( StampInfo stampInfo in stampInfos )
catch ( Exception e )
Console.WriteLine( e );
// Save changes to a file.
contentEditor.Save( StampRemovedPdfFile );
What makes it interesting is that the foreach loop for the stamp infos has 2 items and the first one passes nicely, and the second one fails to the null pointer error.
If I only run the first item from the loop, and save the file after, opening it will show a dialog telling that there is something wrong with the file, but it still works fine.
Attached are files that I have been playing with as well the small app that I’ve been using to investigate the issue.
Any help and ideas how to workaround would be appreciated.