How can I obtain a rectangle for a form field?

Q: I am writing in C#. Given a Field, obtained by iterating over all
fields in a PDF, can I find its rectangle (bounding box)? I want to
add an annotation near it, and Annot’s constructor says it is
required.
-------
A: You could enumerate all annotations on a given page (e.g. as shown
in Annotation sample project - http://www.pdftron.com/net/samplecode.html#Annotation).
Once you encounter an annotation of type Annot.Type.e_Widget you can
get the bounding box for the field using annot.GetRect(). Also you
can
get a field from the annotation using annot.GetWidgetField().

This is further explained in the following KB articles:

[1] http://groups.google.com/group/pdfnet-sdk/browse_thread/thread/ec041d1a1346d6f1/c07549d4e8121ba3
[2] http://groups.google.com/group/pdfnet-sdk/browse_thread/thread/9878a127d43bb511/d78e90595150a3e7

Another approach is to convert a field to annotation. The only
complication is that in PDF a form field may not have a visible
annotation. The following C# pseudocode will convert a form field to a
widget annotation:

// In C#
Obj fld_dict = field.GetSDFObj();
if (fld_dict.FindObj("Rect") != null) {
  Annot widget = new Annot(fld_dict);
  Rect rect = widget.GetRect();
  rect.Normalize();
  ...
}

// In C++
Obj fld_dict = field.GetSDFObj();
if (fld_dict.FindObj("Rect")) {
  Annot widget(fld_dict);
  Rect rect = widget.GetRect();
  rect.Normalize();
  ...
}