Skip to main content
Participating Frequently
August 6, 2023
Answered

How to get absolute page number with script?

  • August 6, 2023
  • 2 replies
  • 743 views

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.

This topic has been closed for replies.
Correct answer m1b

Hi all, from memory I think there is a documentOffset property of Page.

- Mark

2 replies

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
August 6, 2023

Hi all, from memory I think there is a documentOffset property of Page.

- Mark

JakabZsAuthor
Participating Frequently
August 6, 2023

Hi Mark,

 

This is it, thank you very much! 🙂

Legend
August 6, 2023
indexnumberreadonlyThe index of the Page within its containing object.

page.index

JakabZsAuthor
Participating Frequently
August 6, 2023

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.