JavaScript – spawnPageFromTemplate method for templates

This code requires Acrobat Exchange. Ok – finally here’s a example that proves templates are possible. It uses the JavaScript spawnPageFromTemplate method. If you’re too short of time to try this yourself.

To recreate this on your own system, perform the following.

  1. Create a PDF with a front page, and then a subsequent number of pages you wish to use for templates.
  2. Move to the first page you wish to use as a template.
  3. Open the page templates dialog by selecting the ‘Document’, ‘Page Templates’ menuitem.
  4. Add a unique name for the template page. n.b. Remember that the name is case sensitive. You also might want to click the little eyeball, this will hide the templated page from view.
  5. Repeat this for all the pages you wish to use as templates. Be sure to note down the names of the templates, you’ll need them later.
  6. Move to the first page of your PDF. This should not be a template page for this example.
  7. Place a number of form field buttons on the page. Give each one a unique name, and add an ‘OnMouseUp’ event, selecting JavaScript as the action.
  8. Ok – here’s where you need those template names you were asked to note down.
  9. In the JavaScript editor, type the following,

  10. Now repeat this for each button on your front page.
  11. That’s it – you’re all finished. Change back to the ‘hand’ tool and when you click a button a new page is spawned. Voila! (you can spawn as many pages as you like).

You May Also Like

About the Author: Planet PDF Team

Leave a Reply