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

Renumber pages after deletion of spawned page

New Here ,
May 18, 2022 May 18, 2022

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?

TOPICS
JavaScript , PDF forms
1.7K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
May 19, 2022 May 19, 2022

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.

View solution in original post

Translate
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 ,
May 19, 2022 May 19, 2022

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

this.calculateNow();

Translate
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 ,
May 19, 2022 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.

Translate
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 ,
May 19, 2022 May 19, 2022

Did you try it? I think it should work.

Translate
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 ,
May 19, 2022 May 19, 2022

Works fine for me.

Translate
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 ,
May 19, 2022 May 19, 2022

Really? I'm getting "Syntax error missing ) after condition 1"

Translate
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 ,
May 19, 2022 May 19, 2022

Here's what I'm entering: 

if (this.numPages--1); {
this.calculateNow();
}
Translate
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 ,
May 19, 2022 May 19, 2022

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.

Translate
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 ,
May 19, 2022 May 19, 2022

Thanks for sending that, I played around with it and I see what you're saying about the page numbering.

 

I added the condition because I was trying to say, at the document level "IF total page numbers decrease by 1, then calculate now." I don't think I'm doing it right though, or maybe it isn't possible?

Translate
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 ,
May 19, 2022 May 19, 2022
LATEST

You don't need that. You know there are less pages because you deleted one yourself in the previous line of code...

Translate
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