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

How to get absolute page number with script?

Community Beginner ,
Aug 06, 2023 Aug 06, 2023

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.

TOPICS
Scripting , UXP Scripting

Views

317

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

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

- Mark

Votes

Translate

Translate
Guide ,
Aug 06, 2023 Aug 06, 2023

Copy link to clipboard

Copied

indexnumberreadonlyThe index of the Page within its containing object.

page.index

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

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.

 

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

Copy link to clipboard

Copied

LATEST

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

 

@m1b gave correct answer.

 

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

Copy link to clipboard

Copied

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

- Mark

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

Copy link to clipboard

Copied

Hi Mark,

 

This is it, thank you very much! 🙂

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