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

Free Support Forum - aspose.com

Removing Stamps Fails After Saving Stamped File From Adobe Acrobat

Hi everyone,


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 )
{
try
{
contentEditor.DeleteStampById(stampInfo.StampId);
}
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.

Hello There,


Thanks for contacting support.

We are testing the scenario in our environment and will get back to you shortly. Please be patient.


Best Regards,

Hello There,


Thanks for your patience.

I have tested the whole scenario with your code snippet(s) while using latest version of the API, which is Aspose.Pdf for .NET 17.6, and observed that if we fill fields in Adobe Reader, save the file using “Save As” and remove the TextStamp from same file, it gets corrupted.

I have logged an issue as PDFNET-42880 in our issue tracking system, for the sake of detailed investigation. We will further look into this and keep you informed with the status of its resolution. Please be patient and spare us little time.

matti.ketonen:
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.

I was unable to replicate this issue in our environment. After “Saving As” from Adobe Reader, I tried to remove the stamps from the document and API showed correct count in the loop and did not throw any exception. For your reference, I have attached a screenshot.

Would you please share some more information (i.e API version, Application Type, Target Framework), so that we can try to replicate the issue in our environment and address it accordingly.

We are sorry for the inconvenience.


Best Regards,

Hi, and thanks for a quick response again!


The environment where we run our application is Windows with .NET 4.5 and 4.6.
Aspose.PDF API version is 17.6.0.0.

This same has occurred with multiple different Adobe products. One was Adobe Acrobat XI (that our customer uses). My own computer has Adobe Reader DC, for detailed version please see the screen captures.

Thanks for taking time to look at the issue, please let me know if there is any other details I can provide.

Hello There,


Thanks for sharing details.

I have tested the scenario again by modifying file with Adobe Reader DC and was unable to notice wrong count issue of the TextStamp. Furthermore I have also tried to check the count in the same file which you have shared (OoPdfFormExample.Stamped.SavedFromAdobeReader.pdf) and API returned correct count of TextStamps for that file as well.

For your reference, I have also attached the screenshot of both cases. We will really appreciate if you please share a sample console application which reproduces the count issue, so that we can test the scenario again in our environment and address it accordingly.


Best Regards,

Hi and thanks for taking look into the case.


Attached is a solution made with Visual Studio 2017 that I’ve been using to analyze the issue.

You need to have Aspose license file, and you also may need to modify the paths where to find the files, but that should be trivial. I did not include the Aspose libraries from nuget.org nor the redist folder.
Used Aspose versions are:
- Aspose.Cells v17.5.9.0 (redist folder)
- Aspose.Pdf v17.6.0.0 (nuget.org)
- Aspose.Words v17.6.0.0 (nuget.org)

Setting break point to line 313 in Program.cs and executing it should hit first time with no error, and after the second hit once continuing there will be error.

D:\GIT\ART\Testing\AsposeTest\Sample\PDF\OoPdfFormExample.Original.pdf is currently the file that has the issues, it is a copy of OoPdfFormExample.Stamped.SavedFromAdobeReader.pdf file in same folder.

Let me know if I can help more.

Hi There,


Thanks for sharing a sample project.

I have checked the project and observed that you were setting the IDs of the text stamps before adding them inside the PDF and as a result you were having 2 stamps with same ID in the resultant file.

Now when you were calling method DeleteStampById() in the loop, it was deleting both text stamps by one call because of the same ID. Which is why, in second iteration, API was throwing null reference exception as there was no text stamp to delete.

The issue was simply resolved by commenting the SetStampId() method in stamp adding routine (Please check the screenshot) and let the API assign stamp IDs itself.

Moreover, you were observing two stamps in the PDF file, because in the AddStamp() method, you were adding stamp inside “OoPdfFormExample.Original.pdf”, which already had text stamp inside it, so as a result two stamps were present in the resultant file.

In case of you have any further query, please feel free to ask and concerning to above logged issue, we will inform you as soon as we have some definite updates regarding its resolution. Please spare us little time. We are sorry for the inconvenience.


Best Regards,

Hi, and thanks again for good and quick reply!


I understand the case, and as I was assigned to this case I had my thoughts around that stamp ID thing to start with, however after seeing different behavior with file saved from Foxit and Adobe Reader. I thought it might not be that.

I will test bit more, but would appreciate if you have any recommendations how to approach case where customer will have stamped and form based PDF, they want to open it in Adobe Acrobat and fill it, then they save it as a new document which should get a new stamp. Naturally we want to remove only our specific stamp and not any other stamps - assuming there is something else besides the document ID stamp.

Thank you for your help! It has been a pleasure to get to work with your software.

Bit more details of my testing:


Indeed it seems to work better after not setting the stamp ID anymore.

Same observation still persists. The PDF file that was originally saved from Adobe Reader DC / Acrobat XI opens just fine before being processed, but once we remove stamps it will show a message when opening it.

Attached files before and after stamping as well the message coming from Adobe Reader.

Hi,


Thanks for your feedback and sharing more details with us.

We have already tested the scenario in our environment and observed that after removing the stamp from a PDF, which was saved from Adobe Reader after filling data, it got corrupted. We have logged an issue with all relevant details about the scenario including the screenshot which you have shared.

It seemed that something was changing in the document either by Adobe Reader or the API and development team will definitely investigate it as per their development schedule. We have associated the issue ID with this forum thread and as soon as we have some definite updates regarding its resolution, we will let you know.

Please be patient and spare us little time. We are sorry for the inconvenience.


Best Regards,

Hello,

Is there any update on this bug? We tested it with the latest release of Aspose but fillable PDFs are still getting corrupted.

Thanks,

Steve

@slarbig

Thanks for contacting support.

I am afraid that earlier logged issue is not yet resolved due to large number of pending issues in the queue which were logged prior to this issue. As soon as we make some significant progress towards resolution of the issue, we will surely inform you within this forum thread. Please be patient and spare us little time.

We are sorry for the inconvenience.