JavaScript – Finding the Current Page

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.

You May Also Like

About the Author: Kas Thomas

Leave a Reply