Tips & Tricks

Adding Page Number to PDFs

April 01, 2004


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.

PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Quick PDF Library

Get products to market faster with this amazing PDF developer SDK. Over 900 functions and an equally...

Download free demo

Five visions of a PDF Day

In the world of PDFs or as we like to say Planet (of) PDF, a year isn't a real PDF year without an intense few days of industry knowledge sharing.

May 15, 2018
Platinum Sponsor

Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.


Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.