Skip to main content
Inspiring
August 30, 2023
Answered

Resize one page out of 2 page indesign with js

  • August 30, 2023
  • 2 replies
  • 411 views

Hi,

 

I need to resize one out of 2 pages in Indesign with javascript. What would be the correct sintaks for it:

 

myDoc.pages[0].resizeIndividually (8.5,11);

 

Thank you

Yulia

This topic has been closed for replies.
Correct answer Eugene Tyson

Oops that didn't work 

 

Try this

 

var myDoc = app.activeDocument;
var myPage = myDoc.pages[0];

var newWidth = 8.5; // in inches
var newHeight = 11; // in inches

var widthScaleFactor = newWidth / myPage.bounds[3];
var heightScaleFactor = newHeight / myPage.bounds[2];

myPage.resize(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_LEFT_ANCHOR, ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY, [widthScaleFactor, heightScaleFactor]);

2 replies

Peter Kahrel
Community Expert
Community Expert
August 31, 2023

Eugene's method works perfectly fine, but for interest's sake, instead of calculating the new values you could use 

ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH

and simply set the values:

myPage.resize (
  CoordinateSpaces.INNER_COORDINATES, 
  AnchorPoint.CENTER_ANCHOR, 
  ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, 
  [UnitValue (8.5,'in').as('pt'),
  UnitValue (11,'in').as('pt')]
);

Only thing is you need to convert the inch values to points, that's the only unit that .resize() works with.

 

P.

Community Expert
August 31, 2023

Does this work for you?

var myDoc = app.activeDocument;
// Replace 0 if needed
var myPage = myDoc.pages[0]; 

// Page size
var newWidth = 8.5; // in inches
var newHeight = 11; // in inches

// Set dimensions
myPage.resize(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_LEFT_ANCHOR, ResizeMethods.ADDING_CURRENT_DIMENSIONS_TO, [newWidth - myPage.bounds[3], newHeight - myPage.bounds[2]]);
Eugene TysonCommunity ExpertCorrect answer
Community Expert
August 31, 2023

Oops that didn't work 

 

Try this

 

var myDoc = app.activeDocument;
var myPage = myDoc.pages[0];

var newWidth = 8.5; // in inches
var newHeight = 11; // in inches

var widthScaleFactor = newWidth / myPage.bounds[3];
var heightScaleFactor = newHeight / myPage.bounds[2];

myPage.resize(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_LEFT_ANCHOR, ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY, [widthScaleFactor, heightScaleFactor]);
Inspiring
August 31, 2023

Thank you.

 

It's strange that first version did not work. I don't see anything wrong with it. It's not crashing, only not doing anything. But 2nd version works perfectly.