Adding Page Number to PDFs

When creating PDFs from a layout application, you can easily place page numbers on each page. However, when using different producer applications and merging PDF files, you won’t have a chance to add page numbers unless they are uniquely added in the right order in each program that produces the PDFs to be merged together.

Add to this any pages that might be downloaded with Web Capture, and you’ll quickly find a need to create page numbers after the final PDF has been created.

By using a little JavaScript, we can add page numbers easily in Acrobat 5.0.

Create a Button Field.

Select the Form tool from the top level Acrobat toolbar and drag open a rectangle on a page in a PDF file. For the Type, select Button.

Supply a name for the field. In this example I used pageNo for the field name.

In the Field Properties dialog box, click on the Action tab. The default ‘When this happens’ item will be MouseUp. Leave the item selected for MouseUp and click on the Add button.

The Add an Action dialog box will appear. In this dialog box select JavaScript from the pull down menu.

Click on Set Action to open the JavaScript editor

Note: For Windows users, Acrobat 5.0 enables you to use a text editor of choice for editing JavaScript code. Select the Edit -> Preferences -> General menu command to open the Preferences dialog box. Click on JavaScript on the left side of the dialog box to open the JavaScript preferences. On the right side of the dialog box, select the External Editor radio button and click on the Choose button. Navigate to your editor and Select it.

In the JavaScript Editor, enter the code as illustrated left. For an easy copy and paste option, download my Acrobat Forms sample file below.

Note: the code at left will place a page number in the top right corner of each PDF page. To place the page number in a different location, you need to change the coordinates listed between the brackets […] in the first line of code.

When finished in the JavaScript Editor, close the dialog box and save the edits. Click on Set Action when returned to the Add an Action dialog box. Then click OK in the Fields Properties dialog box.

To add the page numbers, click on the Button field you created. Delete the button after creating the page numbers. You can also paste the button into a template where you can keep different JavaScripts for repeated use.

You May Also Like

About the Author: Ted Padova

Leave a Reply