Hi, I am working on a document with 500 images and all of them run beyond the text frame size (W: 5 in, H: 7.7 in). Hence, to fit them to the frame, I tried to use Transform->Scale and set the percentage value to less than 100% and the image got fit into the text frame. However, the problem is with a single selection. Selecting an image every time and setting the scale for 500 objects is a time consuming task. I tried using Object style but it does not incorporate "Scale" option in its palette. I tried using Find/Change option but it does not take anything other than an Object style, hence bringing me back to square one. Then I started a discussion on InDesign for the problem: https://forums.adobe.com/thread/2502461 vinny38 was a kind enough soul to provide two solutions: Solution A //FitAnchorToColumn v2 //Transform anchored objects in order to rescale them to make them fit column width, keeping proportions. //by Vinny if (parseFloat(app.version) < 6) main(); else app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "FitAnchorToColumn"); function main() { if (app.documents.length > 0) { var myDoc = app.activeDocument, docUnits = myDoc.viewPreferences.horizontalMeasurementUnits; app.findGrepPreferences = app.changeGrepPreferences = null; app.findGrepPreferences.findWhat = "~a" var myFound = myDoc.findGrep(); for (i = 0; i < myFound.length; i++) { if (typeof myFound.parentTextFrames[0] != "undefined") { var columnWidth = myFound.parentTextFrames[0].textFramePreferences.textColumnFixedWidth, myObjectWidth = myFound.pageItems[0].geometricBounds[3]-myFound.pageItems[0].geometricBounds[1], myScaleFactor = columnWidth/myObjectWidth, myScaleMatrix = app.transformationMatrices.add({horizontalScaleFactor:myScaleFactor,verticalScaleFactor:myScaleFactor}); myFound.pageItems[0].transform( CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_LEFT_ANCHOR, myScaleMatrix ); } } app.findGrepPreferences = app.changeGrepPreferences = null; } else { alert("Open a document"); } } It worked wonders for the images with respect to the width. It rescaled (and not trimmed) the width of the over bound images to the width of the text frame however, it could not adjust the height of too large images. Thus, Vinny took out the time from his busy schedule and provided the following solution. Solution B //FitAnchorToColumn v3 //Transform anchored objects in order to rescale them to make them fit column width, keeping proportions. //by Vinny if (parseFloat(app.version) < 6) main(); else app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "FitAnchorToColumn"); function main() { if (app.documents.length > 0) { var myDoc = app.activeDocument, docUnits = myDoc.viewPreferences.horizontalMeasurementUnits, myFound; app.findGrepPreferences = app.changeGrepPreferences = null; app.findGrepPreferences.findWhat = "~a"; myFound = myDoc.findGrep(); for (i = 0; i < myFound.length; i++) { if (typeof myFound.parentTextFrames[0] != "undefined") { var columnWidth = myFound.parentTextFrames[0].textFramePreferences.textColumnFixedWidth, columnHeight = myFound.parentTextFrames[0].geometricBounds[2] - myFound.parentTextFrames[0].geometricBounds[0], myObjectWidth = myFound.pageItems[0].geometricBounds[3] - myFound.pageItems[0].geometricBounds[1], myObjectHeight = myFound.pageItems[0].geometricBounds[2] - myFound.pageItems[0].geometricBounds[0], myScaleFactor = columnWidth / myObjectWidth, myScaleMatrix = app.transformationMatrices.add({ horizontalScaleFactor: myScaleFactor, verticalScaleFactor: myScaleFactor }) if (myObjectHeight * myScaleFactor == columnHeight) { return null; } else if (myObjectHeight * myScaleFactor < columnHeight) { myFound.pageItems[0].transform( CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_LEFT_ANCHOR, myScaleMatrix); } else { myFound.pageItems[0].transform( CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_LEFT_ANCHOR, myScaleMatrix ); myFound.pageItems[0].resize( CoordinateSpaces.INNER_COORDINATES, AnchorPoint.CENTER_ANCHOR, ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, [ResizeConstraints.KEEP_CURRENT_VALUE, UnitValue(columnHeight + String(docUnits)).as('pt') ] ); } } } app.findGrepPreferences = app.changeGrepPreferences = null; } else { alert("Open a document"); } } The solution worked for both width and height this time however, it trimmed down the top and bottom part of the over bound images (width got rescaled), instead of rescaling them to fit to the text frame size. Vinny has been of great help but he would not be able to provide more time to the puzzle and I am already grateful to him for providing all the help. I am searching for a solution which could search for all the over bound images and rescale (not trim down) them to fit to the size of the text frame. I urge all the scripting experts to provide guidance in the right direction. Regards, Aman Mittal //FitAnchorToColumn v3 //Transform anchored objects in order to rescale them to make them fit column width, keeping proportions. //by Vinny if (parseFloat(app.version) < 6) main(); else app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "FitAnchorToColumn"); function main() { if (app.documents.length > 0) { var myDoc = app.activeDocument, docUnits = myDoc.viewPreferences.horizontalMeasurementUnits, myFound; app.findGrepPreferences = app.changeGrepPreferences = null; app.findGrepPreferences.findWhat = "~a"; myFound = myDoc.findGrep(); for (i = 0; i < myFound.length; i++) { if (typeof myFound.parentTextFrames[0] != "undefined") { var columnWidth = myFound.parentTextFrames[0].textFramePreferences.textColumnFixedWidth, columnHeight = myFound.parentTextFrames[0].geometricBounds[2] - myFound.parentTextFrames[0].geometricBounds[0], myObjectWidth = myFound.pageItems[0].geometricBounds[3] - myFound.pageItems[0].geometricBounds[1], myObjectHeight = myFound.pageItems[0].geometricBounds[2] - myFound.pageItems[0].geometricBounds[0], myScaleFactor = columnWidth / myObjectWidth, myScaleMatrix = app.transformationMatrices.add({ horizontalScaleFactor: myScaleFactor, verticalScaleFactor: myScaleFactor }) if (myObjectHeight * myScaleFactor == columnHeight) { return null; } else if (myObjectHeight * myScaleFactor < columnHeight) { myFound.pageItems[0].transform( CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_LEFT_ANCHOR, myScaleMatrix); } else { myFound.pageItems[0].transform( CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_LEFT_ANCHOR, myScaleMatrix ); myFound.pageItems[0].resize( CoordinateSpaces.INNER_COORDINATES, AnchorPoint.CENTER_ANCHOR, ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, [ResizeConstraints.KEEP_CURRENT_VALUE, UnitValue(columnHeight + String(docUnits)).as('pt') ] ); } } } app.findGrepPreferences = app.changeGrepPreferences = null; } else { alert("Open a document"); } }
... View more