Skip to main content
Participating Frequently
March 8, 2022
Answered

Acrobat DC - Adding a Page in Middle of Multipage Document with Button Click

  • March 8, 2022
  • 7 replies
  • 8545 views

Hello, 

 

We have created a 16 page PDF with fields on each page for the user to fill out (attached). 

On page 6 we have a button called Add Circuit Breaker Page. This button has the following JavaScript attached to create a duplicate of the Circuit Breaker Test Report page in the PDF. 


var a = this.getTemplate("Circuit Breaker");
a.spawn();
this.calculateNow()

 

We need the new added page to appear as page 7 in the multipage PDF. Instead, the new page is added at the end of the PDF as page 17 - which we do not want. Is there a way for us to make the button click on page 6 to add the new page on page 7 instead of the end of the document? 

 

Thanks for your help,

 

Brian

This topic has been closed for replies.
Correct answer JR Boulay

Replace your script by this one:

 

var a = this.getTemplate("Circuit Breaker");
a.spawn(6, false, false);
this.calculateNow();

7 replies

JR Boulay
Community Expert
March 20, 2023
New Participant
March 28, 2023

Hi,

 

I found another soultions on the web and I was able to fix it. 

JR Boulay
Community Expert
March 17, 2023

"var a = this.getTemplate("???");"

You omitted the template name, see example above.

Acrobate du PDF, InDesigner et Photoshopographe
New Participant
March 17, 2023

how do I name the pages, I tried to put the title of the page and it did not work. I also tried to put the number of the page, also did not work. I tried severl options. All did not give me the ablity to regenerate the page or any page. 

JR Boulay
Community Expert
March 14, 2022

There is another thing you should now.

Enjoy!  😉

 

Acrobate du PDF, InDesigner et Photoshopographe
New Participant
March 9, 2023

Hi

I tried to follow the formella in your comments for my PDF form for action buttons but it did not work. Is it possible if you can help me with my form? 

BarlaeDC
Community Expert
March 14, 2023

Hi,

The file attached does not appear to have any code (unless I just missed it), are you able to upload your file with your attempt so that we can provide feedback on the code you created, this forum is for us to help you, not really for us to do the work for you.

JR Boulay
Community Expert
March 14, 2022

Replace the whole script by:

 

this.getTemplate("Circuit Breaker").spawn(this.numPages-10, true, false);

 

It works fine (tested).

Don't ask me why but in this document if the script don't indicate the page number in a relative way the automatic numbering doesn't work. I suppose it's because page 6 and the hidden template page are identical and contain fields with the same name but I'm not sure.

Acrobate du PDF, InDesigner et Photoshopographe
Participating Frequently
March 14, 2022

@JR Boulay  - this worked perfectly! A couple of us have done some testing and not seeing any problems. Thanks for sending the updates script and alignment screenshot! 

JR Boulay
Community Expert
March 9, 2022

Sure, just change the bRename parameter, like this:

 

var a = this.getTemplate("Circuit Breaker");
a.spawn(6, true, false);
// this.calculateNow(); // this line is useless

 

You should read this, about the Template methods: https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/html2015/Acro12_MasterBook/JS_API_AcroJS/Template_methods.htm?rhhlterm=spawn&rhsyns=%20

Acrobate du PDF, InDesigner et Photoshopographe
Participating Frequently
March 9, 2022

Thank you so much for the solution and the link. The Template options info will be a great resource for us. 

 

Have a great day!

JR Boulay
JR BoulayCorrect answer
Community Expert
March 9, 2022

Replace your script by this one:

 

var a = this.getTemplate("Circuit Breaker");
a.spawn(6, false, false);
this.calculateNow();

Acrobate du PDF, InDesigner et Photoshopographe
Participating Frequently
March 9, 2022

Thank you for the new script! This worked perfectly. Appreciate your help!

BarlaeDC
Community Expert
March 9, 2022

Hi,

 

You can specify a Page number with spawn command, something like

 

a.spawn ( 6);

 

 

Participating Frequently
March 9, 2022

Thank you for responding and helping with my question!