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

How to get absolute page number with script?

Community Beginner ,
Aug 06, 2023 Aug 06, 2023

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.

TOPICS
Scripting , UXP Scripting
466
Translate
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 , Aug 06, 2023 Aug 06, 2023

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

- Mark

Translate
Guide ,
Aug 06, 2023 Aug 06, 2023
indexnumberreadonlyThe index of the Page within its containing object.

page.index

Translate
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 Beginner ,
Aug 06, 2023 Aug 06, 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.

 

Translate
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
LEGEND ,
Aug 06, 2023 Aug 06, 2023
LATEST

In this case - Index refers to the order on the Spread - parent of every Page.

 

@m1b gave correct answer.

 

Translate
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 06, 2023 Aug 06, 2023

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

- Mark

Translate
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 Beginner ,
Aug 06, 2023 Aug 06, 2023

Hi Mark,

 

This is it, thank you very much! 🙂

Translate
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