Skip to main content
Inspiring
Mar 2, 2022 7:55 PM UTC
Answered

Resize page by script

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!

LaubenderCorrect answer
Community Expert
Mar 3, 2022 9:51 AM UTC

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 )

10 replies

LaubenderCommunity ExpertCorrect answer
Community Expert
Mar 3, 2022 9:51 AM UTC

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
Dan-BTPAuthor
Inspiring
Mar 3, 2022 2:45 PM UTC

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
Community Expert
Mar 3, 2022 4:17 AM UTC

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
-Manan