I'm wanting to use ExtendScript javascript to loop through each page of an Adobe InDesign document and change the size of the page to match the visible bounds of all the objects on that page. I'll just ignore any invisible objects.

I know how to loop through pages, select everything on a page, and group them. But I'll need help to figure out how to:

  1. Save the locked states of each visible item on the page to an array so I can unlock all of them in order to be sure to select all visible items on the page before grouping, so I can then be able to return each object to its original state of locked-ness (those little monsters!).

  2. Find the boundary coordinates of the grouped object.

  3. Use the coordinates to send some kind of "resize page corners to these coordinates" kind of command to fit the page to its content.

  4. After ungrouping the objects on the page, restore the lock states of each object.

I'm using Mac OS X El Capitan, Adobe InDesign CC 2018, and Adobe ExtendScript Toolkit CC.


enter image description here becomes enter image description here

  • I don’t think you can resize a page to coordinates; you just resize to a certain size. You’ll probably have to resize first, then set the top left point of the group to 0,0 on the page afterwards. Mar 30 '18 at 14:54
  • Thanks, @Janus. I had also thought about doing it that way, instead. I have been searching for the command to resize the page. Then I'd just be left with unlocking all visible objects, grouping, getting size of group, using the resize page command, moving group to 0,0, ungrouping, and finally setting locked states to what they were prior to this resizing operation.
    – nollaf126
    Mar 30 '18 at 17:22
  • Pretty much, yes. Also, you can set the label property on any ‘PageItem` to any string value you want, so you should be able to store each object’s initial locked in the individual object itself rather than making an array and matching objects. That way, it’s really just three commands in all. Before resizing: item.label = item.locked; item.locked = false;. After resizing: item.locked = item.label. That should make it a bit simpler. (You may need to do some casting, since locked is Boolean and label is a string, but that’s straightforward enough.) Mar 30 '18 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.