The first code snippet traverses all form fields in the document,
whereas the second one traverses all widget annotations on each page.
All widgets are always associated with form fields, whereas a form
field may not be associated with a widget.
As a result you should check that the annotation type is e_Widget when
casting a form field into a widget:
For example:
// In C++
FieldIterator itr = pdfdoc.GetFieldIterator();
for(; itr.HasNext(); itr.Next()) {
Field field = itr.Current();
cout << field.GetName() << endl;
Annot annot(field.GetSDFObj());
if (annot.GetType() != Annot::e_Widget) continue;
Rect bbox = annot.GetRect();
cout << bbox.x1 << "," << bbox.y1 << endl;
}
// In C#
FieldIterator itr = pdfdoc.GetFieldIterator();
for(; itr.HasNext(); itr.Next()) {
Field field = itr.Current();
Console.WriteLine("Field name: {0}", field.GetName());
Annot annot = new Annot(field.GetSDFObj());
if (annot.GetType() != Annot.Type.e_Widget) continue;
Rect bbox = annot.GetRect();
Console.WriteLine("BBox: "....);
}