PDF In-Depth

JavaScript - Finding the Current Page

July 01, 2001


The question recently came up during a discussion with a friend of how (if at all) you can unambiguously determine, programmatically, with JavaScript, what page of a PDF document the user is looking at when a widget is tripped. This becomes an interesting (and important) issue when the complexities of template-spawning are overlaid, so to speak, on the discussion. Suppose the user has spawned 15 template pages, then backtracked through half of them. He clicks into a text field. What page is he on?

Well, if it's a spawned page, all the field names begin with 'P' plus the zero-based page number. But more generally, you can find the current page number by just doing:

var currentPage = this.pageNum;

Again, though, remember that the page numbering is zero-based (like arrays in C). The first page of any document is zero.

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

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
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.