• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Spawn and delete page field numbering fail

New Here ,
Apr 11, 2019 Apr 11, 2019

Copy link to clipboard

Copied

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?

TOPICS
Acrobat SDK and JavaScript

Views

984

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 11, 2019 Apr 11, 2019

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 15, 2019 Apr 15, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 15, 2019 Apr 15, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 15, 2019 Apr 15, 2019

Copy link to clipboard

Copied

Sorry, I was not specific enough.  I would like to spawn a new page and add a unique prefix like a time stamp to each field using javascript to make each page unique.

Basically I want to through code to rename all the fields on a template form that I spawn.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 15, 2019 Apr 15, 2019

Copy link to clipboard

Copied

You can't do that. You can only tell the Template object itself to rename the fields or not, but you can't tell it in what way to do so.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 15, 2019 Apr 15, 2019

Copy link to clipboard

Copied

Unfortunately fields cannot be renamed in a script, they have to be recreated. I don't know why, its just the way Adobe did it. If you're going to go this route, then you shouldn't put fields on the template page at all. Just create them as needed when a new page is spawned.

However, I provided an example methodology in my previous response. Spawn enough pages to automatically create the unique names, then delete the extra pages. This is far less code than recreating new field names.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 16, 2019 Apr 16, 2019

Copy link to clipboard

Copied

https://forums.adobe.com/people/Thom+Parker  wrote

Unfortunately fields cannot be renamed in a script, they have to be recreated. I don't know why, its just the way Adobe did it. If you're going to go this route, then you shouldn't put fields on the template page at all. Just create them as needed when a new page is spawned.

However, I provided an example methodology in my previous response. Spawn enough pages to automatically create the unique names, then delete the extra pages. This is far less code than recreating new field names.

Please elaborate on the second paragraph.  Im not sure I follow.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 16, 2019 Apr 16, 2019

Copy link to clipboard

Copied

LATEST

If you look at the field names on the spawned pages you see that they are prefixed with both the template name and the number of the spawned page.  So if 3 pages are spawned after page 2, the field prefixes will be page3, page4, and page5.  If page 4 is deleted, then you'll have page3 and page5.  If a new page is spawned after the page5 prefix, it will also have the page5 prefix since this is the real page 5. And I believe this is your issue. But if another spawn is done, then you'll have page3,page5, page5, and page6. The extra page is added to get past the page number gap caused by deleting the original page4.  Now you can delete the second page5 to get a unique set of field names.

The trick to this technique is keeping track of the additions and deletions.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines