Skip to main content
Participating Frequently
July 14, 2009
Answered

Resize document to match the content

  • July 14, 2009
  • 1 reply
  • 862 views

Hi,

I would like to resize a document to match its content. This should be done by script. For example I have got only 3 elements in the centre of the document. In this case these objects should be moved all together (like a group) to the left top corner of the document and then the document should be resized properly, so no unused "free space margins" will be left. How can I do it? I will use InDesign Server for this job, controlling it by JavaScript.

Thank you for all comments!

This topic has been closed for replies.
Correct answer Peter Kahrel

This script follows the recipe:

doc = app.documents[0];

g = doc.pages[0].groups.add (doc.pages[0].allPageItems);
bounds = g.geometricBounds;
doc.documentPreferences.pageHeight = bounds[2] - bounds[0];
doc.documentPreferences.pageWidth = bounds[3] - bounds[1];
g.move ([0,0]);

Peter

1 reply

Peter Kahrel
Community Expert
Community Expert
July 14, 2009

A recipe:

- group the three elements

- get the geometric bounds of the group

- resize the page to the dimensions of the groups bounds

- make sure the group is exactly on the page

Peter

Participating Frequently
July 14, 2009

How can I do it by script? On page I can have many elements (textboxes, images, lines, circles, other geometrical stuff), not only 3 - some also grouped, some not. And I have to "cut" the page from all the sides to match exactly the content.

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
July 14, 2009

This script follows the recipe:

doc = app.documents[0];

g = doc.pages[0].groups.add (doc.pages[0].allPageItems);
bounds = g.geometricBounds;
doc.documentPreferences.pageHeight = bounds[2] - bounds[0];
doc.documentPreferences.pageWidth = bounds[3] - bounds[1];
g.move ([0,0]);

Peter