Skip to main content
Obi-wan Kenobi
Legend
September 24, 2016
Answered

Playing with Zoom percentages! …

  • September 24, 2016
  • 3 replies
  • 584 views

Hi all,

I have a document where all pages have different dimensions!

E.g.: a 4-pages document,

page 1 = 40 mm W  x 12 mm H;

page 2 = 185 mm W  x 312 mm H;

page 3 = 151 mm W  x 72 mm H;

page 4 = 229 mm W  x 144 mm H.

When I resize each page to window, I get different zoom-percentages!

page 1 = 925%;

page 2 = 82%;

page 3 = 290%;

page 4 = 172%.

I would like to compare all the percentages and keep the smaller [82%] and apply this zoom to all the pages! 

My beginning is:

var myTarget = app.documents[0];

for (i=0; i < app.layoutWindows.length; i++)

{

app.layoutWindows.zoom(ZoomOptions.FIT_PAGE) ;

myZoom = myTarget.layoutWindows.zoomPercentage;

……

}

……

              

I've no real idea about how finish this script!

Thanks for your help!

(^/) 

This topic has been closed for replies.
Correct answer Loic.Aigon

Hello,

Something like this :

var main = function () {

  var d = app.properties.activeDocument,

  minZoom, ps, p, n, l, zp;

  if ( !d ) return;

  l= d.layoutWindows[0];

  ps = d.pages;

  n = ps.length;

  while (n--) {

  p = ps;

  l.activePage = p;

  l.zoom ( ZoomOptions.FIT_PAGE );

  zp = l.zoomPercentage;

  (!minZoom || minZoom<zp ) &&  minZoom = zp;

  }

  l.zoomPercentage = minZoom;

}

var u;

app.doScript ( "main();",u,u,UndoModes.ENTIRE_SCRIPT, "ReZoom" );

HTH

Loic

Ozalto | Productivity Oriented - Loïc Aigon

3 replies

Peter Kahrel
Community Expert
Community Expert
September 25, 2016

If you're into one-liners, this is the one for you, using the undocumented (in the ESTK) .apply() function:

Math.min.apply (null, app.layoutWindows.everyItem().zoomPercentage);

everyItem() is as good a friend as Math.min!

Peter

Obi-wan Kenobi
Legend
September 25, 2016

Hi Jongware, Loïc and Peter,

Loïc's approach works fine, except a small error at line 14:

(!minZoom || minZoom>zp ) &&  minZoom = zp;

… but I'm interested to explore the "Math.min" way! I'm working on it too!

Thanks to both of you! 

(^/)

Loic.Aigon
Legend
September 25, 2016

Wow Peter, that rocks

Obi-Wan-Kenobi​ what is the error you are facing ?

Loic.Aigon
Loic.AigonCorrect answer
Legend
September 24, 2016

Hello,

Something like this :

var main = function () {

  var d = app.properties.activeDocument,

  minZoom, ps, p, n, l, zp;

  if ( !d ) return;

  l= d.layoutWindows[0];

  ps = d.pages;

  n = ps.length;

  while (n--) {

  p = ps;

  l.activePage = p;

  l.zoom ( ZoomOptions.FIT_PAGE );

  zp = l.zoomPercentage;

  (!minZoom || minZoom<zp ) &&  minZoom = zp;

  }

  l.zoomPercentage = minZoom;

}

var u;

app.doScript ( "main();",u,u,UndoModes.ENTIRE_SCRIPT, "ReZoom" );

HTH

Loic

Ozalto | Productivity Oriented - Loïc Aigon

Jongware
Community Expert
Community Expert
September 24, 2016

Math.min is your friend.

Set myZoom to the zoom of the first document, thenset it to

myZoom = Math.min(myZoom, myTarget.layoutWindows[0].zoomPercentage):

in the loop. At the end, myZoom will contain the smallest value of all.