Q:
I have a pdf document with a submit and print button. If there is only
one set of submit and print buttons on a given page, I am successfully
able to remove them using the following code:
Field printButton =
docTemplate.FieldFind("Form.printButton").Current();
Annot print_annot = new Annot(printButton.GetSDFObj());
docTemplate.PageFind(i).Current().AnnotRemove(print_annot);
//grc Remove Submit Button
Field submitButton =
docTemplate.FieldFind("Form.submitButton").Current();
Annot submit_annot = new Annot(submitButton.GetSDFObj());
docTemplate.PageFind(i).Current().AnnotRemove(submit_annot);
I have a couple of forms where the submit and print buttons appear at
the top and bottom of the page - with the same form field name. Using
the above code code, only the bottom references are removed.
How do I remove all instances of form field annotations with the same
same?
-----
A:
If you have several form-field annotations with the same name, you will
need to call AnnotRemove multiple times.
The following example illustrates how you could implement this
functionality:
static void RemoveAllFields(PDFDoc doc, Page page, String field_name) {
FieldIterator itr = doc.FieldFind(field_name);
for (int counter=0; itr!= doc.FieldEnd();
itr=doc.FieldFind(field_name), ++counter) {
Field f = itr.Current();
// check if the field is a valid annotation (i.e. must have
Subtype key)
if (f.GetSDFObj().FindObj("Subtype") != null) {
// Get the annotation from the Field...
Annot annot = new Annot(f.GetSDFObj());
page.AnnotRemove(annot);
}
}
Example of use:
RemoveAllFields(pdfdoc, pdfdoc.PageFind(page_num).Current(),
"Form.submitButton");