We have a PDF document that we’re trying to remove the annotations from and it’s failing on a single page of that document. I’ve extracted just that page and attached it below. Basically, using the attached document, attempt to run the following code:
Dim Document As Aspose.PDF.Document = New Aspose.PDF.Document(SourceFileName)
Document.Pages(1).Annotations(1).Flatten()
and you’ll receive a null reference exception in return. The same happens if you try the “Delete” method.
There were 10 pages total in the original document, with annotations on 9 of them, and this was the only page that had the issue. We were able to remove or flatten annotations from the other 8 pages that had them, so there’s something odd about this one page. It was also the 9th page in the original document, with the final page being the only one without annotations, so they were the last ones in the document, just in case that makes any difference. If you’d like, I can upload the original, as well.
Can someone help me figure out what’s wrong with those annotations and figure out a way to remove them? I notice there is a PdfAnnotationEditor object in the Aspose.Pdf.Facades namespace - should I be using that instead of going directly at the annotations off the page like we do in the code above?
I would like to share with you that you can flatten all the annotations in a document by Document.Flatten() method, which flattens all those elements with which user can interact (e.g form fields, annotations, etc.). PdfAnnotationEditor can also be used to flatten annotations as in the code snippet below:
Dim editor As New PdfAnnotationEditor()
editor.BindPdf(document)
editor.FlatteningAnnotations()
editor.Save("Output.pdf")
You can delete all annotations on a page by using the code below:
Document.Pages(1).Annotations.Delete()
A particular annotation can be deleted with below line of code:
Document.Pages(1).Annotations.Delete(1)
I hope this will be helpful. Feel free to let us know if you need any further assistance.
Is there a way to flatten the annotations on an individual basis? It’s good that these appear to work on this document even when the original calls I tried caused the null reference exception, but while it looks like we can either use the Document.Pages(1).Annotations.Delete(1) method to delete an individual annotation, we’d also like to be able to do that for flattening - sometimes we don’t want to flatten everything, just specific annotations.
We are glad to know that, things have started working in your environment. However, NullReferenceException is being thrown while flattening a specific annotation. A ticket with ID PDFNET-44264 has been logged in our issue management system for further investigation and resolution. The issue ID has been linked with this thread so that you will receive notification as soon as the issue is resolved.
Just checking in - is there any updated status on this issue, by any chance? Our clients would like to know when we’ll be able to fix this issue for them in our product.
We are afraid PDFNET-44264 is still pending for investigations owing to critical and previously logged tickets. It will be scheduled on its due turn. We will let you know as soon as the ticket will be resolved. We appreciate your patience in this regard.
If you are subscribed to Paid Support, then please request over Paid Support Helpdesk while referring to the ticket ID PDFNET-44264 and the priority will be raised accordingly. If you face any problem while signing in there, then you may create a topic in Purchase Forum and we will assist you accordingly.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.