Skip to main content
Participating Frequently
April 11, 2019
Question

Spawn and delete page field numbering fail

  • April 11, 2019
  • 1 reply
  • 1287 views

I have a form and on that form I have a custom button to spawn a new page -

var template = this.getTemplate("1");

template.spawn(this.numPages, true, false);

this.pageNum = this.numPages-1;

When I add a few pages everything is works properly, fields are renamed etc.  Once I delete a page say page 4 of 5 pages the page deletes fine.  Page is deleted via a custom button that is on the spawned page -

var response = app.alert("Are you sure you want to DELETE page" + (this.pageNum+1) + " ?", 2, 2);

if(nResponse == 4) {

    this.deletePages(this.pageNum,this.pageNum);

    this.pageNum = 0;

}

Now when I spawn a new page after deleting a page it appears to duplicate the last page I spawned.  It does not rename the fields so it populates the fields with data from the last spawned page, any ideas?

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
April 11, 2019

It actually does rename the fields. The spawn function uses the page number to create the new field names. And since a page was deleted, the fields on the new page end up being duplicates of the previous page, which used to have the same page number as the new page.

The spawn function is not that smart. If you want to create and delete pages, then you'll need to work out a methodology that takes this limitation into account, such as spawning pages until there is a unique set of fields, then deleting the intervening pages.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Jeff1776Author
Participating Frequently
April 15, 2019

Is there a way to manually rename fields or just tack on a unique prefix

try67
Community Expert
Community Expert
April 15, 2019

Manually? Sure, just like you would edit any other field.