Skip to main content
Participant
May 31, 2023
Question

Add New Page Javascript Button

  • May 31, 2023
  • 1 reply
  • 990 views

I have a security work shift log MSWord file of which a separate file gets filled out by each subsequent shift. My goal is to create a single file for all future shift logs to be contained. I have created a form file and have added a button at the bottom of the form file page which should invoke the following insert new file javascript when clicked on: 

this.insertPages({nPage:this.numPages-1, cPath:"log-template.pdf"});

 However, after exiting the form editor and saving the file, I click on the button and nothing happens. Both the source and the insert (Log-Template) document forms are in the same directory. Please assist. Files are attached...

 

Thanks, David

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
May 31, 2023

Open the JS Console (Ctrl+J) and you'll see an error message after clicking the button.

The reason is this method require a trusted context to run, such as a folder-level script. If you're the only one who's going to use it, then you can create this script file and install it on your machine and then it would work.

If others need to use it, too, then you would have to do the same on their machines, as well. Oh, and it won't work in Reader, only in Acrobat.

Another option is to create a (hidden) Template page from this file, and then spawn copies from it when new pages are needed. This would not require installing a script file, and would work in Reader.

Thom Parker
Community Expert
Community Expert
May 31, 2023

As noted by Try67, the correct way to add pages to a PDF is to use a Page Template. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often