Skip to main content
Participating Frequently
May 18, 2022
Answered

Renumber pages after deletion of spawned page

  • May 18, 2022
  • 1 reply
  • 1814 views

I have a form with a template for spawned pages. On the tenplate there is a "delete this page" button so users can delete spawned pages. However, I also have a field, "Pages" that shows the page number on each page using the calculation script below:

event.value = (event.target.page+1) + " of " + this.numPages;

I would like to reset "Pages" when a page is deleted, but realized that adding this as a function of the delete button will not work - can't call a script from a deleted page.

 

Is there any other ways to do this?

This topic has been closed for replies.
Correct answer try67

Here's what I'm entering: 

if (this.numPages--1); {
this.calculateNow();
}

Why did you add this condition to the code?

 

Attached is the file I created that demonstrates how it can work. There is one problem with it, though, that if you remove one of the pages in the middle of the file and then spawn a new one the field names on that new page will not be unique and it will also break the page numbering field, but there's no real solution for that. You have to only delete the last page for it to work correctly.

1 reply

try67
Community Expert
Community Expert
May 19, 2022

After deleting the page you can update the fields by calling this command:

this.calculateNow();

Participating Frequently
May 19, 2022

Thank you, I was looking at using this.calculateNow(); but I don't know where to call it from because I need to caclculate after the page has been deleted. So, it can't come from the delete button.

 

In the document javascript, is there a way to express the condition "if a page has been deleted"? I tried if (this.numPages--1); but Acrobat didn't like it.

try67
Community Expert
Community Expert
May 19, 2022

Did you try it? I think it should work.