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

Open to Last Page

ccs717
Registered: Aug 18 2006
Posts: 20
Answered

Greetings,

I need to have a PDF always open to the last page, even when the number of pages is unknown. Any help would be much appreciated.

Craig

My Product Information:
Acrobat Pro 8.1.2
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
You will have to create a document JavaScript to set the document's page number to the zero based number of pages in the doucment.

The code is:

this.pageNum = this.numPages - 1; // go to the last page of the pdf

Dcoumentation aobut JavaScript is llocated at:

[url=http://www.adobe.com/devnet/acrobat/javascript.php/]JavaScript for Acrobat[/url]

[url=http://www.adobe.com/devnet/acrobat/ /]Acrobat Developer Center[/url]

George Kaiser

ccs717
Registered: Aug 18 2006
Posts: 20
Thank you for the reply.

I know the script for navigating to the last page. The part I need help on is writing the script to be triggered when the PDF is opened. There is no preset Document Action choice for openeing a PDF.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
And that is why a document level script is used, the script will run once when the document is opened. All the code in the "Document JavaScript" area is executed upon opening the PDF to at least perform syntax check and tokenize the code for late execution. So if you create a document level JavaScript and do not put the code within a function, it will be executed upon opening the PDF, or if it is put within a function and the function is called from a document level JavaScript after the definition of the function.

If you want to use the "open page" action you have to add code, a logical variable to idicate the code has been run, to make sure the script is not run a scecond time when a user comes back the the first page. Something like:

// see if page has previously been opened
if (bInitialized != true) {
var bInitialized = true; // define initialized logical variable to prevent rerun
this.pageNum = this.numPages - 1; // go to the last page of the pdf
}

George Kaiser

ccs717
Registered: Aug 18 2006
Posts: 20
Thanks again. This is perfect.

I was unaware that "all the code in the Document JavaScript area is executed upon opening the PDF." I was looking for it to be more complicated than that.