Q: I am working on InteractiveFormsTest.cs (InteractiveForms project)
at line# 253, how do I get annotation name. The sample pdf using in
this example contains 4 annotations, I want to know the field names of
these annotations.
------
A: Use field.GetName() to obtain filed name from a field and
widget.GetField() to obtain a field from a widget annotation. The full
sample code is:
...
PageIterator itr = doc.GetPageIterator();
for (; itr.HasNext(); itr.Next())
{
Page page = itr.Current();
int num_annots = page.GetNumAnnots();
for (int i=0; i<num_annots; ++i)
{
Annot annot = page.GetAnnot(i);
if (annot.IsValid() == false) continue;
Rect bbox = annot.GetRect();
Console.WriteLine(" Position: {0:f}, {1:f}, {2:f}, {3:f}",
bbox.x1, bbox.y1, bbox.x2, bbox.y2);
if (annot.GetType() == Annot.Type.e_Widget)
{
pdftron.PDF.Annots.Widget widget = new Widget(annot);
Field fld = widget.GetField();
string field_name = fld.GetName();
....
}
}
}