• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Need script to change page size to items on page in batch

Community Beginner ,
Sep 09, 2024 Sep 09, 2024

Copy link to clipboard

Copied

I have multiple InDesign files that I use to create a brandmarks. Each brandmark is different size. I need help with a script that will change the page size to the items on the page, save, close and move on to the next document. Any help out there is appreciated. 

TOPICS
Scripting

Views

86

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 09, 2024 Sep 09, 2024

Copy link to clipboard

Copied

LATEST

Any help out there is appreciated.

 

Hi @jasons5017064 , You would have to use the resize method, in order to resize a page to its contents. A simple example would be something like this where I’m resizing page 1 to its page items. I’m grouping the page items to get their combined width and height, which might be a problem if you are depending on multiple document layers:

 

//use points for page resize
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

var d = app.activeDocument;
d.zeroPoint = [0, 0];
var p = d.pages[0]
var api = p.pageItems;
var tg;
if (api.length == 1) {
	tg = api[0]
} else {
    //group page items to get bounds—moves everything to top layer, is that OK?
    tg = d.groups.add(api);
}
//get the group’s width and height
var b = tg.geometricBounds;
var h = b[2] - b[0]
var w = b[3] - b[1]
//resize the page
p.resize (CoordinateSpaces.INNER_COORDINATES,AnchorPoint.CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h])

tg.move([0,0])

app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;

 

 

Before and after:

 

Screen Shot 25.png

 

 

Screen Shot 24.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines