• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script to go to first page

New Here ,
Feb 09, 2020 Feb 09, 2020

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 10, 2020 Feb 10, 2020

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

...

Votes

Translate

Translate
Community Expert ,
Feb 09, 2020 Feb 09, 2020

Copy link to clipboard

Copied

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?

David Creamer: Community Expert (ACI and ACE 1995-2023)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 09, 2020 Feb 09, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 10, 2020 Feb 10, 2020

Copy link to clipboard

Copied

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();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 10, 2020 Feb 10, 2020

Copy link to clipboard

Copied

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){}
}
}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 10, 2020 Feb 10, 2020

Copy link to clipboard

Copied

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();

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 10, 2020 Feb 10, 2020

Copy link to clipboard

Copied

Thanks so much - it works perfectly!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 22, 2024 Aug 22, 2024

Copy link to clipboard

Copied

Hi.  I am trying to figure out how to do this exact thing.  In a pdf document, I'd like to add to each page a button or link so users can go to the first page in the document.

 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 22, 2024 Aug 22, 2024

Copy link to clipboard

Copied

LATEST
quote

Hi.  I am trying to figure out how to do this exact thing.  In a pdf document, I'd like to add to each page a button or link so users can go to the first page in the document.

 

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


By @virginia_9272

 

You need to start a new thread as the one you've replied to - is about completely different and unrelated thing.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines