Form field templating and naming

Q: I am trying to duplicating a page which already exists in a form
using doc.PagePushBack and then filling in dyntamically some field
values on the newly created page. The copy part seems to work ok
except the naming structure is also duplicated. How do I access the
newly created field when the name is exactly the same?

F[0].P[0].name <- is item on first page
F[0].P[1].name <- is field on 2nd page

when creating a dupicate of page #2 I get another F[0].P[1].name field
created??? Shouldn't this be F[0].P[2].name?


When copying PDF page the form field names are not changed. You could
rename the field names using Field.Rename() method. This is illustrated
in the third code snippet in InteractiveForms sample project
( see 'Form

I thought of this already, but problem is how do I tell which field I
am renaming since they both have the same name. If I could tell which
field to rename then I could tell which field I need to fill. Want I
need is the ability to tell which page the each field is on.

You can access form fields on a given page by traversing all widget
annotations on the page.
For example:

Page page = doc.PageFind(1).Current(); // get the first page in the
int num = page.GetNumAnnots();
for (int i = 0; i<num; ++i) {
Annot annot = page.GetAnnot(i);
if (annot.IsValid() && annot.GetType() == Annot.Type.e_Widget) {
Field field = annot.GetWidgetField();
string fieldName = field.GetName();
// field.Rename(…)…