Copy link to clipboard
Copied
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!
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
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 )
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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 )
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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:
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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;
Find more inspiration, events, and resources on the new Adobe Community
Explore Now