RE: [PDFNet] How to identify selected annotations

Currently there is no existing method in PDFNet. I have to track them myself...

int[] SelectedAnnots = null; //Array to keep track of the selected annots

//Place this in the OnMouseDown event
int annot_num = page.GetNumAnnots();
for (int i = annot_num; i >= 0; i--) //Count Backwards to capture proper Z-Order selection for overlapped annotations {
  Annot annot = page.GetAnnot(i);
  if (annot.IsValid() == false) continue;
  Rect box = annot.GetRect();
      double x = e.X;
      double y = e.Y;
      ConvScreenPtToPagePt(ref x, ref y, page_num);
      if (box.Contains(x, y))
    if (e.Button == MouseButtons.Left && Control.ModifierKeys == Keys.Control)
      //Create new array if null
      if (SelectedAnnots == null)
        SelectedAnnots = new int[annot_num];
      //Add to selection
      SelectedAnnots[i] = 1;
    else if (e.Button == MouseButtons.Left)
      //Clear selection Array
      //Add to selection array
      SelectedAnnots = new int[annot_num];
      SelectedAnnots[i] = 1; //1 = selected, 0 = not selected

//Call this to remove selected Annots
public void removeAnnot(int page_num)
  Page page = GetDoc().GetPage(page_num);
  for (int i = SelectedAnnots.GetUpperBound(0); i >= 0; i--) //Count down! When one is deleted, it will change the index of those after
    if (SelectedAnnots[i] != 0)

  //Clear selections
  SelectedAnnots = null;

-----Original Message-----
From: [] On Behalf Of
Sent: Wednesday, November 16, 2011 4:34 PM
Subject: [PDFNet] How to identify selected annotations

I am trying to create a popup menu to delete annotations. The problem occurs with multiple annotations. How do I determine which annotations are selected to know which ones to delete? I have also tried to trigger a keystroke to replicate the "Delete" key, but none of the following attempts work:


KeyEventArgs ke = new KeyEventArgs(Keys.Delete); base.OnKeyDown(ke); base.OnKeyUp(ke);

KeyPressEventArgs kp = new KeyPressEventArgs((char)Keys.Delete);


You received this message because you are subscribed to the "PDFTron PDFNet SDK" group. To post to this group, send email to To unsubscribe from this group, send email to For more information, please visit us at