Skip to main content
Participant
January 21, 2025
Answered

Assistance with Script to Add and Delete Page in Adobe Acrobat Pro using Page Templates

  • January 21, 2025
  • 3 replies
  • 1144 views

I watched the video posted by PDF Form Javascript on YouTube which showed a way to add additional pages and delete them (https://www.youtube.com/watch?v=tlq0NCxamjg). 

 

The problem I ran into was it seems that the script deletes any additional pages added after the template page. I'm looking to incorporate this script to add two separate categories for a tenant portal, I'd like to generate an area for those on the lease (multiple people) and a separate portion of the form for references. The problem is the number of pages will be contingent on the renter and therefore not uniform. I'm trying to work on a script which will allow me to add and delete pages in two separate areas without deleting additional pages not related to the necessary criteria. For instance, if I have (3) renters in an apartment, I'd like to add additional pages for say (3) references, and be able to delete a reference and tenant without deleting other pages in the form. Any help, greatly appreciated!

Correct answer Thom Parker

The delete script, is set to always delete the last page.  

Use this script to delete the page on which the delete button is placed. 

 

this.deletePages(event.target.page);

 

3 replies

Participant
January 22, 2025

Sorry about that, attached is a crude example. I want to be able to generate multiple rental applicant pages in order. Right now, if I create an additional applicant, it creates page 3 below the applicant vehicle information. Eventually I'd like to be able to use the same coding to add more than one vehicle, but again try to maintain the order of pages to correspond to the vehicle section of the form instead of the new pages being generated after the last current page.

PDF Automation Station
Community Expert
Community Expert
January 22, 2025

For the spawn method, setting the nPage parameter to this.numPages will insert the page at the end of the document.  If you want it to insert after the current page, change this.numPages to this.pageNum+1;  See nPage in the Spawn method:

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#spawnpagefromtemplate

Thom Parker
Community Expert
Community Expert
January 22, 2025

Please post the script you are using and explain how the document is setup. We are not going to watch a try and figure out what you did. 

Or post the form. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
PDF Automation Station
Community Expert
Community Expert
January 21, 2025

Can you post your form so your inquiry is more understandable?  Here's an article on adding and deleting pages:

https://pdfautomationstation.substack.com/p/buttons-that-add-and-delete-pdf-pages