Applying a menu bar to all page of a PDF

The following example shows you just how easy it is to add a menubar to all the pages of a PDF through the use of a PDF template. By using a template you can apply the same field across all pages. Tom’s example includes a button that takes the user to the first page of a document as well as a print button.

Download the PDF version with full instructions (76K:PDF).

The menubar is created from a template hidden at the end of the PDF, which gets spawned to every page using JavaScript. The idea came from needing to put a menubar on every page in a document.

The fields are given unique names according to page number. To create your own, first insert a template at the end of a document. Second, use the Tools >> Forms >> Page Templates … menu item to name the template and turn it off. Third, open the Tools >> Forms >> Document JavaScripts… menu item and add the following JavaScript code:

// Inserts template named 'menu' over all pages in document 
// only when template hasn't yet been inserted. This code can
// be removed after the template has been spawned.

// The numFields < 4 is one more than the
// number of fields in the original document.
// Doing this keeps the template from
// spawning more than once.
if (this.numFields < 4) {
var n = this.numPages;
for (i = 0; i < n; i++){
this.spawnPageFromTemplate ('menu', i, true);

Taken from Adobe Acrobat Technical Note #5186, Acrobat Forms JavaScript Object Specification.

You May Also Like

About the Author: Planet PDF Team

Leave a Reply