When you create a PDF using Chrome’s “Save as PDF” command, the links in the document are stored as annotations. Acrobat can read the file and the links work as expected. However, when we try to remove those links using Aspose.Pdf, we get a System.NullReferenceException.
Here is a test PDF that was created using a recent Chrome release: Test File.pdf (36.6 KB)
This document has 25 link annotations on the first page. The code to delete the first one would simply be:
Dim Document = New Aspose.Pdf.Document(SourcePath)
Dim Annotations = Document.Pages(1).Annotations
After executing the final line, we receive the null reference exception, but the count of the parent collection does go down. However, saving and reopening the document restores the annotation, so it’s not actually deleted.
If, instead, you try to flatten the LinkAnnotation using its Flatten method, the same failure happens. The Hyperlink property of the LinkAnnotation is null. The Action property of the LinkAnnotation is a GoToURIAction, and has the correct URI, which we’re able to change. We need to be able to remove it completely, though, so that won’t be adequate. Also, if you view the LinkAnnotation in the debugger, there’s a protected property called “message1” with the text “There is a problem with an annotation. Required entry is absent.”
Is there anything we can do to remove the LinkAnnotation objects from this document? The link works properly in Acrobat, and doesn’t appear to be missing anything that’s actually required, so I’m curious about the message1 value I mention above, and also curious about why we can’t remove the object.
Thanks for any information on this,