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

Resize page by script

Explorer ,
Mar 02, 2022 Mar 02, 2022

I have a JavaScript script that opens a Letter size document containing one page, adds some text frames to the page, and then resizes them to fit their contents. Then I want to resize the page (or the document) down to the overall size of the text frames (approx. 5" wide and 3" high). I can accomplish what I want in InDesign by selecting the Page Tool, setting Liquid Page Rule to Off, and entering the width and height values. I cannot figure out how to do it in JavaScript. Help! Thanks!

TOPICS
Scripting
2.5K
Translate
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

correct answers 2 Correct answers

Community Expert , Mar 02, 2022 Mar 02, 2022

Something like the following should work. This will resize the first page of the active document to new dimensions of 400*500 points

 

var doc = app.documents[0]
doc.pages[0].layoutRule = LayoutRuleOptions.OFF
var bb = BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS
var a = AnchorPoint.TOP_LEFT_ANCHOR
var rm = ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH
var nbb = [400, 500]
doc.pages[0].resize(bb, a, rm, nbb)

 

-Manan

Translate
Community Expert , Mar 03, 2022 Mar 03, 2022

Hi Dan,

test the script with pages of a facing-pages document and with ones from a non-facing-pages document.

You might see a difference in behavior, because in the case of a facing-pages document there is a spine where a page will be "glued" to when resized.

 

Regards,
Uwe Laubender

( ACP )

Translate
Community Expert ,
Mar 02, 2022 Mar 02, 2022

Something like the following should work. This will resize the first page of the active document to new dimensions of 400*500 points

 

var doc = app.documents[0]
doc.pages[0].layoutRule = LayoutRuleOptions.OFF
var bb = BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS
var a = AnchorPoint.TOP_LEFT_ANCHOR
var rm = ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH
var nbb = [400, 500]
doc.pages[0].resize(bb, a, rm, nbb)

 

-Manan

Translate
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 ,
Mar 03, 2022 Mar 03, 2022

Hi Dan,

test the script with pages of a facing-pages document and with ones from a non-facing-pages document.

You might see a difference in behavior, because in the case of a facing-pages document there is a spine where a page will be "glued" to when resized.

 

Regards,
Uwe Laubender

( ACP )

Translate
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
Explorer ,
Mar 03, 2022 Mar 03, 2022

I did both of your suggestions (page.resize as shown and non-facing-pages document) and got exactly what I wanted. Thanks very much for your help!

Translate
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
Participant ,
Jun 06, 2025 Jun 06, 2025

Hi, is there a way of programmatically mimicking the page resizing in the UI whereby you can use e.g. top-center to individually resize items in a spread of facing pages? When I try this I'm getting the "glued to spine" effect!

Translate
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 ,
Jun 06, 2025 Jun 06, 2025

Hi @ukzembla , There is the resize method. This sets the active page to 300 x 600 points using a top center anchor

 


app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var p=app.activeWindow.activePage
//the new width and height in points
var w = 300
var h = 600
//resize using top center anchor
p.resize (CoordinateSpaces.INNER_COORDINATES,AnchorPoint.TOP_CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h])
app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;

 

Screen Shot 32.png

 

Translate
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 ,
Jun 06, 2025 Jun 06, 2025

When I try this I'm getting the "glued to spine" effect!

 

Sorry I missed @Manan Joshi post. Facing page docs always have a spine imitating a (glued or sewn) bound book’s spine. You can setup a non facing page document as spreads and pull the pages apart—in that case the script would do this

 

 

Screen Shot 35.png

 

Screen Shot 36.png

Translate
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
Participant ,
Jun 06, 2025 Jun 06, 2025

Hm, so there's no way you're aware of (programmatically) to do the equivalent of, e.g.

- click page tool, set anchor to be top center

- select both pages of a master spread
- reduce width and height by (say) 10mm

?

For my purposes (minor resizing of books to a slightly different trim, only a few mm different) I don't really want to mess around too much or even do anything that would cause any text reflow (typically this is for long novels)

Translate
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 ,
Jun 06, 2025 Jun 06, 2025

If the document has been setup as facing pages there can be no separation between the pages with or without scripting. Most printed books are folded not cut at the spine prior to binding.

 

I don’t think you need a script. Select all the pages in the Pages panel then with the Pages tool selected change the width and height in the Transform panel. Here I’m changing the trim size from 8"x10" to 7"x9". Set your desired Referense Point an the Transform panel:

 

Screen Shot 41.png

 

 

Screen Shot 42.png

Translate
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
Participant ,
Jun 06, 2025 Jun 06, 2025

Yep, I can do it relatively easily, but was hoping to make a script to semi-automate resizing books for US equivalents of a British trim size, exporting and then quitting in a single click as it's likely to be a regular thing for me. Not extremely difficult to do, just trying to be efficient and I assumed scripting would offer more or less the same options as the UI!

Translate
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 ,
Jun 07, 2025 Jun 07, 2025
LATEST

and I assumed scripting would offer more or less the same options as the UI!

 

It does. This would resize all the pages to A4.

 

app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var p=app.activeDocument.pages
//the new width and height in points, A4 in this case
var w = 595.276 
var h = 841.89

for (var i = 0; i < p.length; i++){
    p[i].resize (CoordinateSpaces.INNER_COORDINATES,AnchorPoint.TOP_CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h])
};  
app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;

 

Translate
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