How to write a javascript for delete page button on spawned page

Explorer ,
Nov 12, 2020

Copy link to clipboard

Copied

I've created a form that contains a template page that is spawned using a button. I want the users to be able to delete the spawned pages by either all with a reset form button or by a delete page button on the spawned page they want to delete.

 

The reset form button works with the javascript:

this.deletePages(2, this.numPages-1);

 

but

 

For the delete page button I have this script

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

 

It works in removing the page but a window pops up as "Bad Parameter". I think I'm missing something.

 

Additionally I have a field that populates the total spawned pages with the script

var numpag = this.numPages - 1;
event.value = numpag;
this.calculateNow();

 

But when the page is delete or the form is reset, it doesn't update. Please help!

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

66

Likes

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

How to write a javascript for delete page button on spawned page

Explorer ,
Nov 12, 2020

Copy link to clipboard

Copied

I've created a form that contains a template page that is spawned using a button. I want the users to be able to delete the spawned pages by either all with a reset form button or by a delete page button on the spawned page they want to delete.

 

The reset form button works with the javascript:

this.deletePages(2, this.numPages-1);

 

but

 

For the delete page button I have this script

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

 

It works in removing the page but a window pops up as "Bad Parameter". I think I'm missing something.

 

Additionally I have a field that populates the total spawned pages with the script

var numpag = this.numPages - 1;
event.value = numpag;
this.calculateNow();

 

But when the page is delete or the form is reset, it doesn't update. Please help!

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

67

Likes

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
Nov 12, 2020 0
Adobe Community Professional ,
Nov 12, 2020

Copy link to clipboard

Copied

This is an example:

 

this.deletePages({nStart: 1, nEnd: 2 });

 

See how I used this part of that script in this thread: 

 

https://community.adobe.com/t5/acrobat/confirmation-checkboxes/m-p/11588429?page=1#M285711

 

 

Likes

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
Reply
Loading...
Nov 12, 2020 0
Adobe Community Professional ,
Nov 12, 2020

Copy link to clipboard

Copied

If the script is only deleting a single page, then do not include the end page. As specified in the JavaScript Reference:

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_Acro...

 

I think you misunderstand how the "calculateNow()" function works.  This function forces all calculation scripts on the form to run. This function should not be used in a calculation script, because, it can potentially cause an infinate loop. However, I think Adobe already thought of this and they block the use of this function in a calculation.  

But anyway, if the "number of pages script" is in a calculation , then the "calculateNow()" needs to be in the code that either spawns or deletes pages, not in the calculation script itself.  

 

 

 

Likes

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
Reply
Loading...
Nov 12, 2020 1
Explorer ,
Nov 12, 2020

Copy link to clipboard

Copied

I corrected the calculateNow() parts in the form. Thank you.

 

For the delete button I do just want it to delete the spawned page the delete button is on. The user can spawn 10 pages when they only want 9 so they would delete that last page. When I test it by deleting the last page spawned, it removes the page but I still get a "Bad parameter" message popup. If I delete a page in the middle of the spawns it removes it with no issue.

Likes

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
Reply
Loading...
Nov 12, 2020 0
Adobe Community Professional ,
Nov 12, 2020

Copy link to clipboard

Copied

It may be more helpful if you can share what exactly are you using  with the "this.getTemplate().spawn  method in your script .

 

It may be possible that your script overinfaltes the file with this action and then the pages get out of order or something . If that would e the case, maybe the delet pages script needs to be re-adjusted.... just guessing. 

Likes

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
Reply
Loading...
Nov 12, 2020 0
Adobe Community Professional ,
Nov 13, 2020

Copy link to clipboard

Copied

Did you remove the second parameter form the delete? 

Ex:

this.deletePages(event.target.page);

 

As stated in the JavaScript Reference, only the first parameter is used when deleting a single page.

Using "event.target.page" is more acurate for the page number because it is specifically the number of the page the button is on (as long as there is only one button with that name).  "this.pageNum" could actually be different depending on how the page is scrolled. 

 

Does the page delete, even though you get the error message? 

One way to debug this, is to use a "console.println" statment in the code to display the exact page number used as well as any other useful info for nailing down the issue. 

You'll find a tutoial here on how to do this (see the Console Window video):

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

 

 

Likes

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
Reply
Loading...
Nov 13, 2020 1