Copy link to clipboard
Copied
Hi,
I'm working on a script where I'd like to know on which page a certain text appears.
I know that this works:
finds = doc.findText();
myPage = finds[0].parentTextFrames[0].parentPage.name;
But it gives me the name of the page, not the absolute number. I need to decide whether the page is within the first n pages of the document or not.
I have written a function which uses the for loop to go through the pages from 1 to n, and compares them to the id of myPage. It works, but I wonder if there is a more simple solution? Is there a way to convert to absolute numbering? Please advise.
Hi all, from memory I think there is a documentOffset property of Page.
- Mark
Copy link to clipboard
Copied
index | number | readonly | The index of the Page within its containing object. |
page.index
Copy link to clipboard
Copied
Hi Pickory,
Thank you, but unfortunately this does not help 😞
The index refers only to the containing object, which is the spread here. So using 2 page spreads every page's index is either 0 or 1. My first try was this:
myPageNum = finds[0].parentTextFrames[0].parentPage.parent.index*2 + finds[0].parentTextFrames[0].parentPage.index;
This worked more or less, as the index of the spread x 2 plus the index of the page whitin the spread gave me the page number - but for the page 1 it was zero whereas for page 2 it was 2. And it fails if there's a spread of more than two pages, or sections with single and double page spreads.
Copy link to clipboard
Copied
In this case - Index refers to the order on the Spread - parent of every Page.
@m1b gave correct answer.
Copy link to clipboard
Copied
Hi all, from memory I think there is a documentOffset property of Page.
- Mark
Copy link to clipboard
Copied
Hi Mark,
This is it, thank you very much! 🙂