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

Free Support Forum - aspose.com

System.InvalidCastException: Unable to cast object of type 'Aspose.Pdf.Annotations.LinkAnnotation' to type 'Aspose.Pdf.Annotations.MarkupAnnotation'

Hi team,

I’m trying to iterate thru all of Annotations in order to be able to “disable” and/or custumize certain properties of annotation and the PDF documents. While trying to do this, I use this code:
// Loop through all the annotations per page
foreach (MarkupAnnotation annotation in pdfDocument.Pages[i].Annotations)
{
annotation.Contents = null;
annotation.Title = null;
annotation.Subject = null;
annotation.Color = null;
annotation.RichText = null;
}
This works well for some annotations types, but I’m getting System.InvalidCastException: Unable to cast object of type ‘Aspose.Pdf.Annotations.LinkAnnotation’ to type ‘Aspose.Pdf.Annotations.MarkupAnnotation’. exception when a different type of annotation is found in the page. In this case, a Link Annotation.
Now, what I’d like to do is go thru all annotations and make those or similar annotation properties disappear from the PDF.
How can I accomplish this? I’m using Aspose PDF version 19.9.0.0

@rreinoso

I request you to upgrade to the latest version and share your feedback. If you still face the issue then share PDF file so that we may proceed further with investigation on our end.