annotManager.getAnnotationsList();
annotManager.deleteAnnotation();
deletedWidgets.push({
name: widget.fieldName,
widgetIndex: getWidgetIndex(widget)
});
annotManager.deleteAnnotation(widget);
function getWidgetIndex(widget) {
var field = widget.getField();
var widgetIndex = 0;
for (var i = 0; i < field.widgets.length; ++i) {
if (field.widgets[i] === widget) {
widgetIndex = i;
break;
}
}
return widgetIndex;
}
std::vector < std::pair < UString, int > > toDelete;
// use your own data here, but here is an example
toDelete.push_back(std::pair < UString, int > (UString("Radio Button1"), 2));
toDelete.push_back(std::pair < UString, int > (UString("Check Box1"), 0));
for (UInt32 i = 0; i < toDelete.size(); ++i) {
std::pair < UString, int > currentOperation = toDelete[i];
UString field_name_ustr = currentOperation.first;
std::string field_name = field_name_ustr.ConvertToUtf8();
FieldIterator itr = doc.GetFieldIterator(field_name_ustr);
if (itr.HasNext()) {
bool still_valid = true;
for (int i = 0; i < currentOperation.second; ++i) {
itr.Next();
if (!itr.HasNext() || itr.Current().GetName() != field_name_ustr) {
still_valid = false;
break;
}
}
if (still_valid) {
// find the parent page
Field current_field = itr.Current();
Page p(current_field.GetSDFObj().FindObj("P"));
cout << "Processing Field " << current_field.GetName() << endl;
if (p.IsValid()) {
bool annotation_deleted = false;
// find the annotation on this page and remove it
for (UInt32 i = 0; i < p.GetNumAnnots(); ++i) {
if (p.GetAnnot(i).GetSDFObj() == current_field.GetSDFObj()) {
// delete the annotation
p.AnnotRemove(i);
annotation_deleted = true;
}
}
if (!annotation_deleted) {
cerr << "Could not find Widget with field name " << field_name << " in the parent page" << endl;
} else {
cout << "Successfully deleted Widget with field name " << field_name << endl;
}
} else {
cerr << "Required key P (the page reference) is missing" << endl;
}
} else {
cerr << "Could not find Widget with field name " << field_name << " at index " << currentOperation.second << endl;
}
} else {
cerr << "Could not find Widget with field name " << field_name << endl;
}
}