Skip to main content
Participant
Feb 9, 2020 10:39 AM UTC
Answered

Script to go to first page

Hello,

Can someone please help with a script that I can apply to a book which will leave each document on the 1st page?

Thanks in advance.

This topic is closed to new replies. Start a new post to keep the conversation going.
brian_p_dts
brian_p_dtsCorrect answer
Community Expert
Feb 10, 2020 4:53 PM UTC

Thanks - that works for the active doc.

Please show me how to insert your script into the following so that it applies to all docs in the book:

var myBook = app.activeBook;
for(var n=0; n < myBook.bookContents.length; n++)
{
app.open(File(myBook.bookContents[n].fullName.toString()));
for (var i = 0; i < app.activeDocument.allPageItems.length; i++)
{
var myPageItem = document.allPageItems[i];
if(myPageItem.getElements()[0].constructor.name == "TextFrame")
{
myPageItem.select();
try{
app.scriptMenuActions.itemByID(71442).invoke();
}catch(e){}
}
}
}


Just throw the select() function before the end of your outer for loop, like so: 

 

var myBook = app.activeBook;
for(var n=0; n < myBook.bookContents.length; n++)
{
app.open(File(myBook.bookContents[n].fullName.toString()));
for (var i = 0; i < app.activeDocument.allPageItems.length; i++)
{
var myPageItem = document.allPageItems[i];
if(myPageItem.getElements()[0].constructor.name == "TextFrame")
{
myPageItem.select();
try{
app.scriptMenuActions.itemByID(71442).invoke();
}catch(e){}
}

}

app.activeDocument.pages[0].select();

}

8 replies

Dave Creamer of IDEAS
Community Expert
Community Expert
Feb 9, 2020 9:34 PM UTC

Can you give more info?

First page of the book or each document in the book? 

What is your output--PDF?

Are you looking a button or something that the user can click to go to the first page?

Do you just want the PDF just to open on a particular page?

Translate
David Creamer: Community Expert (ACI and ACE 1995-2023)
Participant
Feb 10, 2020 7:39 AM UTC

It's completely unrelated to the PDF - purely for convenience with the book docs.

I currently use a script which updates all TOCs in the book documents - it's great but it leaves each document on the last master page.

So I want to either add to the end of the TOC script or use a separate one that will bring each document in the book to the first "real" page.

Thanks.

Translate
brian_p_dts
Community Expert
Community Expert
Feb 10, 2020 8:45 AM UTC

So if I understand correctly, the script leaves you with the last master page active? Use LayoutWindow or select() to get back to the first page, depending on your needs: 

 

app.layoutWindows[0].activePage = docRef.pages[0];
 
or 
 
docRef.pages[0].select();
Translate