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

JavaScript to determine if the last page of the document you are working on is left or right

New Here ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

Help me!

I want to know the JavaScript that shows whether the last page of the document I am working on is left or right.

For example..

var a = 8;

if (a === 8) {

 Load the aaa.txt file into the last page on the right.

} else (a ===7) {

 Load the bbb.txt file to the last page on the left.

}

TOPICS
Scripting

Views

469

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 , Jan 23, 2021 Jan 23, 2021

Use the page's side property:

if (app.documents[0].pages[-1].side === PageSideOptions.LEFT_HAND) {
   // Load bbb.txt
} else {
   // Load aaa.txt
}

This works in left-to-right and in right-to-left documents. The last page's document offset is the same in both types of document.

P.

Votes

Translate

Translate
New Here ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

For example..

var a = 8;

if (a === 8) {

 Load the aaa.txt file into the last page on the right.

} else  {

 Load the bbb.txt file to the last page on the left.

}

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 ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

if (app.activeDocument.pages.lastItem().documentOffset % 2 == 0) { 
    //page is odd (usually right)
} else {
    //page is even (usually left)
} 

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 ,
Jan 23, 2021 Jan 23, 2021

Copy link to clipboard

Copied

Thank you for your 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 ,
Jan 23, 2021 Jan 23, 2021

Copy link to clipboard

Copied

Use the page's side property:

if (app.documents[0].pages[-1].side === PageSideOptions.LEFT_HAND) {
   // Load bbb.txt
} else {
   // Load aaa.txt
}

This works in left-to-right and in right-to-left documents. The last page's document offset is the same in both types of document.

P.

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 ,
Jan 23, 2021 Jan 23, 2021

Copy link to clipboard

Copied

LATEST

Thank you for your 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