Skip to main content
Participating Frequently
May 1, 2014
Question

resize pages based on elements

  • May 1, 2014
  • 1 reply
  • 1781 views

Hey,

need to do this:

I have multiple pages on single InDesign document, each page has one single text frame which contains a table with different heights. I'd need to resize the pages based on the size of the text frame. Since there is more than 100 pages, doing it by hand with Page Tool is a bit of frustrating task.

Any idea how to make a script/action out of it?

This topic has been closed for replies.

1 reply

Kai Rübsamen
Participating Frequently
May 1, 2014

Hi,

this is the first time I try to resize something. Try the following lines:

var curDoc = app.activeDocument;

var allPages = curDoc.pages;

hM = curDoc.viewPreferences.horizontalMeasurementUnits;

vM = curDoc.viewPreferences.verticalMeasurementUnits;

curDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;

curDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;

for ( var i = 0; i < allPages.length; i++ ) {

    var curPage = allPages;

    var tf = curPage.textFrames[0];

    var tfWidth = tf.geometricBounds[3] - tf.geometricBounds[1];

    var tfHeight = tf.geometricBounds[2] - tf.geometricBounds[0];

    curPage.resize(CoordinateSpaces.INNER_COORDINATES,

                                AnchorPoint.TOP_LEFT_ANCHOR,

                                ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,

                                [tfWidth, tfHeight]);

                                tf.move([0,0]);                           

}

curDoc.viewPreferences.horizontalMeasurementUnits = hM;

curDoc.viewPreferences.verticalMeasurementUnits = vM;

Some questions to the advanced scripters:

1. What does 'CoordinateSpaces.INNER_COORDINATES' means?

2. How can I check the values of 'CoordinateSpaces'?

3. Why do I get an error, if the rulers are set to 'mm' instead of points? I assume that it has something to do with margins? But I’m not able to find the real problem.

Thanks

Kai

Adobe Expert
May 1, 2014

Kai,

> What does 'CoordinateSpaces.INNER_COORDINATES' mean?

See http://www.indiscripts.com/post/2014/03/coordinate-spaces-and-transformations-1

> 2. How can I check the values of 'CoordinateSpaces'?

> 3. Why do I get an error, if the rulers are set to 'mm' instead of points?

resize()  defaults to points and doesn't accept strings like "100 mm". If you want to set values as e.g. mm, you need UnitValue to convert those values to points, as in:

     . . .

     . . .

     ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,

     [UnitValue('100','mm').as('pt'), UnitValue('150','mm').as('pt')]);

Peter

Kai Rübsamen
Participating Frequently
May 1, 2014

Hi my friend,

thanks for your explanation and the link for Marcs PDF .

best

Kai