Shapes aren't drawn on the good page when the document setup is 'facing page' in InDesign (CEP/JavaScript)

92 views Asked by At

I am creating an InDesign plugin where one of the features is to draw shapes on a given page.

I get a drawing from the backend with the page number on which it should be drawn.

For this, I do : app.activeDocument.pages[index] to get the page I want.

Unfortunately, I realized that this technique only works when the pages are not facing each other like this :

enter image description here

When the pages are facing each other like this :

enter image description here

, the shapes on page 3 will be drawn on page 2 instead of on page 3.

Here, the drawings are on the right page :

enter image description here

But here, the rectangle isn't on the right page :

enter image description here

I also tried to draw the shape in a raw way by doing app.activeDocument.spreads[indexSpread].pages[1], which should logically write the note on the 2nd page of the board in question except that it is always drawn on the 1st page of the board.

Here is my code to draw the rectangle :

var doc = app.activeDocument;
var page = doc.pages[pageIndex-1];
var myRectangle = page.rectangles.add();
1

There are 1 answers

2
Yuri Khristich On BEST ANSWER

To address pages inside a spread use the page origin coordinates:

app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

var doc = app.activeDocument;
var page = doc.spreads[indexSpread].pages[1];
var myRectangle = page.rectangles.add();