parsingAnnot.IsValid() - Exception when parsing annots on a page

Hi,

I’m using PWDViewWPF and C#.

I have a doc loaded in the view, on a page I’m looking at I have 2 existing annotations (highlights) and I can see them just fine. When I add a third one that overlaps the existing two, I have to run some business logic to determine if the mouse down/up points exist within any existing annots on the page, and if so merge them, and remove the existing annots.

The merge part isn’t the issue I’m having, the issue is why one of the eixsitng Annot parses as being invalid ?

This is the relevant code:

if (_newAnnotationAdded)
{

//2) Loop existing annots on page, and if the parsing one has points within the new one, they overlap and are to be merged.
currentPage = _pdfDocument.GetPage(_pdfViewer.CurrentPageNumber);

if (currentPage != null) {
annot_num = currentPage.GetNumAnnots();
}

for (int i = 0; i <= annot_num; ++i)
{

Annot parsingAnnot = currentPage.GetAnnot(i);

if (parsingAnnot.IsValid() == false || parsingAnnot.GetType() !=
Annot.Type.e_Highlight) continue;

Rect parsingAnnotRect = parsingAnnot.GetRect();

…continue with my business logic for merging.
}

I have some debug statements and breakpoints going that tell me a few things:

  1. The annot just added is included in the GetNumAnnots, so I add code to ignore it when iterating the page’s annots (by skipping if the parsing rect point are exact matches to the new one just created) so I only look at the pre-exisiting annots, of which there are two !
  2. One of the pre-existing annots parses through just fine.
  3. The second pre-existing annot ALWAYS throws an exception at the code in red, and never gets processed. The annot exists on the page, and is a nice yellow color, so it looks pretty valid to me.

Question(s):

  1. The code in red I got from other posts, and the logic of it seems contrary to the task at hand, because a) the annots on the page are valid (or at least you would think so since they did render to the page), and b) they are all type highlight…but to parse them I have to negate those conditions in that statement…doesn’t make alot of sense to me ?
  2. Why does the second, seemingly valid annot, fail to make it past the condition in red ?
  3. If I change the condition in red to look at IsValid == true || GetType() == highlight …then everything breaks…so to parse good highlights, I have to test them as bad…weird.

Why does the second existing annot on the page throw an exception all the time ?

I tried locking and unlocking the document before and after the code in red, and that just breaks everything…

Please advise,

Barry

Hi Barry, is the second annot valid at some point earlier?

You can take a look at the contents in the PDF by using the COSEdit tool that comes with the windows SDK downloads. If the second annot in question is on page 2 for example you would look at /root/pages/kids/1/Annots/1 is the entry you want. This might shed some light.

Or if that does not help, if you can, send the document to support for us to look at.