Skip to main content
Inspiring
November 12, 2020
Question

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

  • November 12, 2020
  • 2 replies
  • 6902 views

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!

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
November 12, 2020

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_AcroJS%2FDoc_methods.htm%23TOC_deletePagesbc-20&rhtocid=_6_1_8_23_1_19

 

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.  

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Inspiring
November 13, 2020

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.

ls_rbls
Community Expert
Community Expert
November 13, 2020

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. 

ls_rbls
Community Expert
Community Expert
November 12, 2020

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