These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Getting Page numbers

msstrend
Registered: Mar 15 2007
Posts: 53

How to get the page numbers of the PDF into any external format?
Please help.

konsta
Registered: Jul 26 2006
Posts: 8
I'm not sure I understand your question, but I will make some assumptions and give it a crack.

To get the total number of pages in a document, use the doc property numPages. After you get that value, you can iterate through all of the pages using a for loop. For example, if you are writing a document-level javascript (meaning that the javascript is stored within the document that you will be using it), you can use the object "this" to refer to the document. The following code will loop through all of the pages in a document and printout the page number and the number of words on each page.

var intTotalPages = this.numPages ;
for ( var i = 0; i < intTotalPages; i++ ) {
var intWordsOnPage = this.getPageNumWords ;
console.println( "Page Number " + ( i + 1 ) + " has " + intWordsOnPage + " words on it.") ;
}

Each page is a separate object and all of these objects are stored in a zero-based array, so to get the actual page number, you need to add 1 to the array index.

If you want to know what page you are on, you use the pageNum property of the doc object. You can also use this property to go to a specific page. For example:

var intCurrentPage = this.pageNum ;

will put the current page number into the variable intCurrentPage. If you want to use any of the Acrobat methods or properties that need a page number, you should use this value. If you want to printout (or send to another application) the physical page number, then you add 1 to the internal page number (which is because the default for the first value in a JavaScript array is 0. In reality, the value you get from the pageNum property is not really the page number, but rather the page index, but since that would cause a whole other set of confusing problems, Adobe opted to call it the value the page number).

If you wanted to move yourself to a specific page in a document (say the 5th page), you would use the JavaScript:

this.pageNum = 4 ;

I hope that helps. If not, let me know a little more about what you are trying to do, specifically, I'm not too sure what you mean by "external format."

---Andrew