Copy link to clipboard
Copied
My code.:
var sel = app.documents[0].selection;
pp = sel[j].parentPage;
Now there are three conditions that can identify left and right pages, as well as single pages
pp.side == PageSideOptions.RIGHT_HAND
pp.side == PageSideOptions.SINGLE_SIDED
pp.side == PageSideOptions.LEFT_HAND
I now want to handle the first and last pages separately. It would be helpful if I could determine whether the current page is a spread.
A page is not a spread ever afaik. Spread contains pages. A page's parent will give you the spread. So if you want to know if a page is the only one in the spread then something like the following would work
if(pp.parent.pages.length == 1)
alert("PP is the single page in its spread.")
If you want the first and last page of a spread you can use the following. Do note that if the spread has only 1 page then both these pages would be same
var firstPageOfSpread = pp.parent.pages[0]
var lastPageOf
...
Testing the side doesn’t tell you if it’s a first or last page—the document could be setup like this:
You can use the page’s document offset to test for first or last like this:
var sel = app.documents[0].selection[0];
if (sel.parentPage.documentOffset == 0) {
$.writeln("Selection is on first page")
}
if (sel.parentPage.documentOffset == app.documents[0].pages.length-1) {
$.writeln("Selection is on last page")
}
Copy link to clipboard
Copied
You can check the number of pages in the parentPage’s parent (the spread)
var sel = app.documents[0].selection[0];
$.writeln("The selection’s spread contains " + sel.parentPage.parent.pages.length + " pages")
Copy link to clipboard
Copied
A page is not a spread ever afaik. Spread contains pages. A page's parent will give you the spread. So if you want to know if a page is the only one in the spread then something like the following would work
if(pp.parent.pages.length == 1)
alert("PP is the single page in its spread.")
If you want the first and last page of a spread you can use the following. Do note that if the spread has only 1 page then both these pages would be same
var firstPageOfSpread = pp.parent.pages[0]
var lastPageOfSpread = pp.parent.pages[-1]
-Manan
Copy link to clipboard
Copied
Testing the side doesn’t tell you if it’s a first or last page—the document could be setup like this:
You can use the page’s document offset to test for first or last like this:
var sel = app.documents[0].selection[0];
if (sel.parentPage.documentOffset == 0) {
$.writeln("Selection is on first page")
}
if (sel.parentPage.documentOffset == app.documents[0].pages.length-1) {
$.writeln("Selection is on last page")
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now