27 Replies Latest reply on Jun 19, 2018 2:52 AM by vinny38

    Scale all images at once in InDesign

    amanm5143 Level 1

      Hi,

      I am working on a document with 500 images and all of them run beyond the text frame size. 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. (Kindly note that all images are inline hence, I cannot use ScaleGraphics to resize them all at once).

       

      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. I urge all the InDesign experts to provide their thoughts on the following question related to the problem:

       

      Is it possible to apply Scale option to all the images at once - a script or plugin or simple technique?

       

      Any guidance in the right direction would be greatly appreciated. Hope to receive a positive response.

      Regards,

      Aman Mittal

        • 1. Re: Scale all images at once in InDesign
          Colin Flashman Adobe Community Professional

          Have you tried this script from in-tools?

           

          Scale Graphics Script | in-tools.com

          1 person found this helpful
          • 2. Re: Scale all images at once in InDesign
            amanm5143 Level 1

            Hi Colin,

            Thank you for taking out the time and replying to the discussion. As mentioned earlier, I had tried ScaleGraphics script. However, the script does not work for inline images (anchored images); it only works on unachored ones.

             

            Regards,

            Aman Mittal

            • 3. Re: Scale all images at once in InDesign
              vinny38 Level 5

              Hi.

              Interesting question.

               

              Could you give this script a try and report back?

               

              //FitAnchorToColumn v1
              //Fit anchored objects to column width keeping proportions
              //by Vinny
              
              
              if (app.documents.length > 0) {
                  var myDoc = app.activeDocument;
              
              
                  app.findGrepPreferences = app.changeGrepPreferences = null;
                  app.findGrepPreferences.findWhat = "~a"
                  var myFound = myDoc.findGrep();
              
              
                  for (i = 0; i < myFound.length; i++) {
                      if (typeof myFound[i].parentTextFrames[0] != "undefined") {
                          var columnWidth = myFound[i].parentTextFrames[0].textFramePreferences.textColumnFixedWidth;
                          myFound[i].pageItems[0].resize(
                              CoordinateSpaces.INNER_COORDINATES,
                              AnchorPoint.TOP_LEFT_ANCHOR,
                              ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH, [UnitValue(columnWidth + 'mm').as('pt'), ResizeConstraints.KEEP_CURRENT_PROPORTIONS]
                          );
                      }
                  }
              
              
              } else {
                  alert("Open a document");
              }
              

               

              Script detect column width for a anchored object, then resize it.

              Text will then reflow, so make sure you have consistent number of columns and column width (using primary text frames?), otherwise reflow could mess the whole thing.

               

              fit.gif

               

              Edit:

              Oh I forgot to say that script only resizes the anchored object itself, not the imported graphic.

              In my example, I used an Object style for my pics, with auto-resize ON

              1 person found this helpful
              • 4. Re: Scale all images at once in InDesign
                amanm5143 Level 1

                Hi Vinny,

                Thank you for taking out the time to find a solution and work upon the same. I tried your solution following these conditions:

                1. All the images were anchored

                2. I had set the Auto-sizing Option in the Text Frame Options to "Width and Height"

                3. Anchor Position was not changed.

                4. Column width and numbers were of fixed number - 1

                 

                Though the script worked but it cropped the right side part of the image to fit to the width and bottom part to fit to the height. Basically, it trimmed the images to fit to the size of text frame. Additionally, it didn't run on every text frame; I had to select each text frame and run the script again to make the desired changes.

                 

                I think my problem would get resolved if I am able to use the Transform tool to change the percentage value from 100% for all images, BUT, at a single go.

                 

                I appreciate your hard work and am grateful to you for trying things out. I hope The report contained all the necessary info. Looking forward to your reply.

                Regards,

                Aman Mittal

                • 5. Re: Scale all images at once in InDesign
                  vinny38 Level 5

                  amanm5143  wrote

                   

                  2. I had set the Auto-sizing Option in the Text Frame Options to "Width and Height"

                  [...]

                   

                  Though the script worked but it cropped the right side part of the image to fit to the width and bottom part to fit to the height. Basically, it trimmed the images to fit to the size of text frame.

                  Well, I actually meant Object style > Fitting options, not Text Frame Options > Auto-sizing.

                  This is why your images got cropped.

                  Now, thinking about it, maybe auto-fitting is not what you want...

                  So, lets think differently. Instead of resizing the frame, let's rescale it.

                  Give this version 2 script a try and tell me if it works for you.

                  Besides, I modified it because not everyone works in millimeters... It now should work whatever measurement units are in use.

                  I also "wrapped" it, so you can CTRL-Z it now...

                   

                  //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[i].parentTextFrames[0] != "undefined") {
                                  var columnWidth = myFound[i].parentTextFrames[0].textFramePreferences.textColumnFixedWidth,
                                  myObjectWidth = myFound[i].pageItems[0].geometricBounds[3]-myFound[i].pageItems[0].geometricBounds[1],
                                  myScaleFactor = columnWidth/myObjectWidth,
                                  myScaleMatrix = app.transformationMatrices.add({horizontalScaleFactor:myScaleFactor,verticalScaleFactor:myScaleFactor});
                                   
                                  myFound[i].pageItems[0].transform(
                                      CoordinateSpaces.INNER_COORDINATES,
                                      AnchorPoint.TOP_LEFT_ANCHOR,
                                      myScaleMatrix 
                                  );
                              }
                          }
                  
                  
                          app.findGrepPreferences = app.changeGrepPreferences = null;
                  
                  
                      } else {
                          alert("Open a document");
                      }
                  }
                  

                   

                   

                  amanm5143  wrote

                   

                  Additionally, it didn't run on every text frame; I had to select each text frame and run the script again to make the desired changes.

                  Hmmmm... that's strange. I don't know what to tell you. It should affect the whole document...

                  Let's see if version 2 magically solves it ^^

                  1 person found this helpful
                  • 6. Re: Scale all images at once in InDesign
                    amanm5143 Level 1

                    Hey Vinny,

                    Thank you for putting in so much effort into this. I am overwhelmed by your effort to help me out. I tried version 2 of the script and it does appear to rescale things to the column, and not trim it by a factor. So, it is great work - Top-Notch and the script is now affecting all the items. However, there are two things that I would like to clear out:

                     

                    1. The script only rescales the width of the image and not the height. So, is it possible to add the same to the script?

                     

                    2. I would like to all my images to follow Anchor Object Position - Inline or Above Line with centre alignment. Whenever, I try to change the position to Inline, all my text and image jump and vanishes from the frame. However, the moment I change the position to Custom, everything comes back and I find few images having their columns fixed and not their heights.

                     

                    I have just started to learn the intermediate functions of InDesign an have not been able to able figure this thing out.

                    Request you to guide me regarding the same, whenever you get spare time on your hands. I would not like to impose anything as you have already done a lot and am too grateful for the same.

                     

                    Thanks a lot, Vinny! You are a great person.

                    Regards,

                    Aman Mittal

                    • 7. Re: Scale all images at once in InDesign
                      amanm5143 Level 1

                      Hey Vinny,

                      Regarding the latest, I have got an update. The script does adjust the height as well, it is just that it does not rescales the height for the very large images though it does the same for column width. So, is there a way to tweak the script to make InDesign rescale the height upto the height of the text frame?

                       

                      Regards,

                      Aman Mittal    

                      • 8. Re: Scale all images at once in InDesign
                        Chad Chelius Adobe Community Professional

                        Are you applying an Object style to the images? If so, you should be able to enable "keep within top/bottom column boundaries" in the anchored object options to keep the images within the frame bounds.

                        • 9. Re: Scale all images at once in InDesign
                          vinny38 Level 5

                          If I understand you correctly, you have cases where your anchored image is very high and overflows after applying the script.

                          Just like this example:

                          overflow.jpg

                          In which case, you can try version 3 of the script which will resize height while trimming top and bottom of the image:

                           

                          //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[i].parentTextFrames[0] != "undefined") {
                                          var
                                              columnWidth = myFound[i].parentTextFrames[0].textFramePreferences.textColumnFixedWidth,
                                              columnHeight = myFound[i].parentTextFrames[0].geometricBounds[2] - myFound[i].parentTextFrames[0].geometricBounds[0],
                                              myObjectWidth = myFound[i].pageItems[0].geometricBounds[3] - myFound[i].pageItems[0].geometricBounds[1],
                                              myObjectHeight = myFound[i].pageItems[0].geometricBounds[2] - myFound[i].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[i].pageItems[0].transform(
                                                  CoordinateSpaces.INNER_COORDINATES,
                                                  AnchorPoint.TOP_LEFT_ANCHOR,
                                                  myScaleMatrix);
                                          } else {
                                              myFound[i].pageItems[0].transform(
                                                  CoordinateSpaces.INNER_COORDINATES,
                                                  AnchorPoint.TOP_LEFT_ANCHOR,
                                                  myScaleMatrix
                                              );
                                              myFound[i].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");
                              }
                          }
                          

                           

                          Now, I won't have much time today to work on that script, but feel free to post it to the InDesign Scripting forum if you have further requirements.

                          Scripting experts will be happy to help, and very possibly will come up with a much better and efficient script for you.

                           

                          About the anchored object options, as Chad suggested, you should work with an object style.

                           

                          Thanks for your kind comments, it was a very interesting question and puzzle, and I thank you for helping me improving my scripting skills ^^

                          • 10. Re: Scale all images at once in InDesign
                            amanm5143 Level 1

                            Hi Chad,

                            Thank you for taking out the time and replying to the thread. Much appreciated! Regarding the solution you mentioned, I do not want to apply Custom Positioning in the Anchored Object Options, as I would like the images to be Inline. Hence, this restriction does away with the "Keep within top/bottom column boundaries" option.

                             

                            If I do Custom Positioning, the text does not jump due to the size of the images. However, I have restriction to use Inline positioning. Therefore, rescaling the images to text frame width and height helps in achieving that goal. "Keep within top/bottom column boundaries" option definitely keeps the images linked to the frame but as the size of a few images exceed the length of the text frame, I have to rescale them, one by one. That is why, I asked for a solution which could rescale the images and vinny38 was kind enough to provide a solution.

                             

                            Thank you for the help and suggestion!

                            Regards,

                            Aman Mittal

                            • 11. Re: Scale all images at once in InDesign
                              amanm5143 Level 1

                              Hey Vinny,

                              You cannot imagine the amount of gratitude I feel for you for taking out time from your busy schedule to help me out. It is just amazing how much of an amazing person you are and I can't thank you enough for doing this.

                               

                              Regarding the script, it worked wonders for fixing the image to the size of the text frame however as you pointed out, it trimmed the top and bottom part instead of rescaling the image which resulted in a problem for the project.

                               

                              It would have been fantastic if version 3 could have taken the attributes of version 2's Width rescaling (which adjusted the width to the text frame without trimming down the content of the image) and applied to Height as well. But, it is still pretty great and I can't be more grateful.

                               

                              For the moment, I will stick to version 2 of the script and adjust the height of the leftover images manually. If you ever get spare time to work upon the script again at any moment in the future, it would be great. If you don't, no issues! You have already helped me reduce the workload by 25% which is pretty amazing.

                               

                              Thanks a lot for all the help and for giving your due time to the thread. Its been great knowing you! Stay blessed, always!

                              Regards,

                              Aman Mittal

                              • 12. Re: Scale all images at once in InDesign
                                vinny38 Level 5

                                Aman,

                                 

                                I'm not quite sure I understand what is your problem/request...

                                 

                                Version 3 should work the same than version 2 : rescale anchored object H & W proportionally, up to column width.

                                But v3 will also resize height (by trimming top and bottom), only in case the image is so high that it wouldn't fit the text frame height while fitting the width. This is meant to avoid anchored object to overflow, which would be a real mess...

                                 

                                I think I would understand better what you mean if you'd provide a couple of screenshots (normal view + invisible characters on) ...

                                 

                                Cheers

                                • 13. Re: Scale all images at once in InDesign
                                  amanm5143 Level 1

                                  Hey Vinny,

                                  Thank you for taking out the time again from your busy schedule. You are absolutely right. Version 3 rescales anchored object H & W proportionally, up to column width. However, it "resizes height by trimming the top and bottom part" which led to loss of image content for me. I was trying to achieve to what you did to column width with column height as well. A solution which could rescale the H & W proportionally up to column width and height, just like a Transform Tool while not trimming an part of the image.

                                   

                                  I will try to as elaborate as I can be:

                                  Text Frame size: 6.14 in x9.21 in

                                  When I try to flow the file through “Place”, it shows like this (here the Anchored Object Positioning, by default is: InLine)

                                  Untitled.png

                                  Then I change the Anchored Object Positioning to Custom for all graphic frames and the file starts to flow:

                                  Untitled1.png

                                  Untitled2.pngUntitled3.pngUntitled4.png

                                  As you can see, few of the images are well within the frame size (5 in x 7.7 in) while few of them are too large to be accommodated to the text frame size. So, I follow the approach of Transform Tool and change the percentage value to rescale (not trim) them to fit to the text frame size (5in x 7.7in).

                                  As I have to deal with 500+ images, using Transform Tool for each one of them becomes a humongous task. Therefore, I was looking for a solution which could "search and rescale (both width and height) the out of bound images in the entire document at a single go within the text frame size" without:

                                  • Trimming any part of the image as it leads to loss of image content
                                  • Changing the size of already in-bound images (the solution shall leave all those images unattended and unscaled which are already under the text frame size)

                                   

                                  I hope I was able to clearly make you understand the problem and required solution. Thank you for giving this your due consideration.

                                  Regards,

                                  Aman Mittal

                                  • 14. Re: Scale all images at once in InDesign
                                    vinny38 Level 5

                                    Hi Aman

                                    I wish I could help further, but I really don't understand your workflow...

                                    You are talking about custom positioning, but where is your anchored marker positioned?

                                    On a single line? At the beginning of a paragraph?

                                    Sans-titre-2.jpg

                                    Do you want a custom position in order to have this kind of layout? (calculating from the position of the anchor marker up to column bottom):

                                    bunny.jpg

                                    Or is it supposed to fit height like this (with no trimming, meaning extra white space around the picture):

                                    Sans-titre-4.jpg

                                     

                                    Before thinking of scripting scenario, you should really think about pros and cons of either inline or custom positioning.

                                    E.g: What about this kind of situations (custom positioning):

                                    Sans-titre-5.jpg

                                    Custom positioning can be very tricky...

                                     

                                    Your screenshots are very hard to understand, maybe you could post screenshots (bigger size) showing exactly what you want to achieve, and not what you currently get...

                                     

                                    Vinny

                                    • 15. Re: Scale all images at once in InDesign
                                      amanm5143 Level 1

                                      Hi vinny38

                                      Thank you for taking out the time from your busy schedule and replying, again. It is my fortune that I got in touch with such a dedicated person, like you. Big Thanks!!!

                                      Regarding your concern, I understand that maybe I am not able to define the problem, properly. I will try to accommodate all your concerns this time.

                                      Checkpoints:

                                      The word document that I using to Place has “Inline” images.

                                      INDD Document’s Text Frame size: 5 inch (Width) x 7.7 inch (Height)

                                      Removed the image content – Consider the image frame as an image only.

                                      Workflow requires all the images to be positioned Above Line with Centre Alignment and not have Custom positioning

                                       

                                      I place a file through Place Gun which gives me the following result:

                                      1.png2.png

                                       

                                      You may notice two things:

                                      • Anchored image is out of the frame size in terms of width and not height (out of bounds).
                                      • And, there is a plus sign which suggests an overflow because there are many images in the document which run beyond the text frame size either in terms of just width (like the above example) or just height or in few cases, through both ends.

                                       

                                      I check the Anchored Object Positioning for the image which suggests that the images are line, as stated earlier (which is fine with me as my workflow requires all the images to be positioned Above Line with Centre Alignment and not have Custom positioning).

                                      3.png

                                      However, in order to deal with “overflow” problem I change the positioning of the Anchored Graphics to Custom to ascertain the images which need rescaling. This results in full flow of the text.

                                      4.png

                                      The moment you change the position to Custom, all the images comes to the sidelines of the frame and the text flows completely.

                                      5.png

                                      As I told you earlier, I am dealing a hell lot of images of varying sizes in the same document:

                                      • Image 1 - You could see a particular sized image which if out of width but not in height
                                      • Image 2 – Both with and height are in-bound (well within frame size) and do not need rescaling
                                      • Image 3 – Out of bound in terms of height but not in terms of width

                                      6.png

                                      7.png

                                      8.png

                                       

                                      What I am trying to achieve:

                                      A solution which:

                                      • Searches through the entire document for images running out of bounds (bounds defined as Text frame size: 5 inch x 7.7 inch -  width , height)  either
                                        • In terms of width but not in terms of height (Reference: Image 1)
                                        • In terms of height but not in terms of width (Reference: Image 3)
                                        • In terms of both width and height
                                      • Rescales but does not trim all the out of bounds running images to fit under the frame size, as shown in the below snap.
                                      • I used Transform Tool and changed the percentage values to make the Image 3 fit under frame size and brought back the anchor positioning to Above Line with Centre alignment. This time, the image did not overflow and text the flows perfectly.

                                      10.png

                                      • Leaves in-bound images unattended - Image 2 is not rescaled as its size was well under the text frame size

                                      9.png

                                       

                                      I hope this explains the process. In case, I am not still not able to convey the problem clearly, then, do let me know. I will send you a sample document for the same. Big Thanks to you!!!

                                      Regards,

                                      Aman Mittal

                                      • 16. Re: Scale all images at once in InDesign
                                        Laubender Adobe Community Professional & MVP

                                        Hi Aman,

                                        in priciple that would mean:

                                         

                                        1. Open the story in the Story Editor Window.

                                        2. Cut the character that constitutes the anchored image and paste it to the first insertion point of a different text frame whose dimensions will allow to see the full image. Maybe you'll need a gigantic text frame ( who knows? ).

                                        3. Resize the image

                                        4. Cut and paste the character that constitutes the resized image back to the Story Editor.

                                         

                                        With a script it's (nearly) the same.

                                        To change dimensions you must move the image out of it's original story.

                                        Fact is: When in overset you cannot tell its dimensions.

                                         

                                        In case your pasteboard cannot hold it's dimensions, image's too large, you have to change pasteboard dimensions of the document or you move it to a new document where the pasteboard can hold it.

                                         

                                        Regards,
                                        Uwe

                                        • 17. Re: Scale all images at once in InDesign
                                          amanm5143 Level 1

                                          Hey Uwe,

                                          This is true and I follow these two approached only. Either I follow Transform Tool or I cut paste image in a new document and rescale it to bring it back to the original document. You are absolutely right that in over set, one cannot tell the dimensions. That is the reason, I spoke about custom positioning as it helps in getting rid of the over set text problem as a temporary fix. This way, I don't have to cut paste the image to another frame. I just go through the same document, select the image frame I want to re-scale and use the Transform Tool, then and there. In such a way, without changing the pasteboard dimensions of the document, you are able to fit the image to the frame.

                                           

                                          It is just that when you are working with a batch of 500 images or so, working on each one of them become a time consuming task and a script helps you in saving that time.

                                           

                                          Hence, I thought of consulting with the experts.

                                          Regards,

                                          Aman

                                          • 18. Re: Scale all images at once in InDesign
                                            vinny38 Level 5

                                            Aaaahhh it sure is much more clear now...

                                            So basically, it's about managing overflow...

                                            As Uwe pointed out, we apparently can't get dimensions of an overset object.

                                            But, it seems to be possible to rescale it.

                                             

                                            So, I modified the script in a way it first look for overset objects, reduce them to 5% (assuming this would be small enough to make them fit in the flow), then, rescale them as described earlier.

                                             

                                            Since Uwe/Laubender "the scripting expert" popped in, you might expect a more efficient way to handle your issue. I tested it on a short document with little images, and it seems to be working fine, but with a 500+ images doc, script might be slow enough.

                                             

                                            Again, I think a moderator should move this to the Scripting forum

                                             

                                            So, please try this version 4:

                                             

                                            //FitAnchorToColumn v4
                                            //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();
                                            
                                            
                                                    // first rescale overflow objects to 5%
                                            
                                            
                                                    for (i = 0; i < myFound.length; i++) {
                                                        if (typeof myFound[i].parentTextFrames[0] == "undefined") {
                                                          //  alert(myFound[i].pageItems[0].geometricBounds);
                                                            myFound[i].pageItems[0].transform(
                                                                CoordinateSpaces.INNER_COORDINATES,
                                                                AnchorPoint.TOP_LEFT_ANCHOR,
                                                                app.transformationMatrices.add({
                                                                    horizontalScaleFactor: .05,
                                                                    verticalScaleFactor: .05
                                                                })
                                                            )
                                                        }
                                                    }
                                            
                                            
                                                    // then fit everything to column width if possible, otherwise to column height
                                                    
                                                    app.findGrepPreferences = app.changeGrepPreferences = null;
                                                    app.findGrepPreferences.findWhat = "~a";
                                                    myFound = myDoc.findGrep();
                                            
                                            
                                                    for (i = 0; i < myFound.length; i++) {
                                                        if (typeof myFound[i].parentTextFrames[0] != "undefined") {
                                                            var
                                                                columnWidth = myFound[i].parentTextFrames[0].textFramePreferences.textColumnFixedWidth,
                                                                columnHeight = myFound[i].parentTextFrames[0].geometricBounds[2] - myFound[i].parentTextFrames[0].geometricBounds[0],
                                                                myObjectWidth = myFound[i].pageItems[0].geometricBounds[3] - myFound[i].pageItems[0].geometricBounds[1],
                                                                myObjectHeight = myFound[i].pageItems[0].geometricBounds[2] - myFound[i].pageItems[0].geometricBounds[0],
                                                                myScaleFactorH = columnWidth / myObjectWidth,
                                                                myScaleFactorV = columnHeight / myObjectHeight,
                                                                myScaleMatrixH = app.transformationMatrices.add({
                                                                    horizontalScaleFactor: myScaleFactorH,
                                                                    verticalScaleFactor: myScaleFactorH
                                                                }),
                                                                myScaleMatrixV = app.transformationMatrices.add({
                                                                    horizontalScaleFactor: myScaleFactorV,
                                                                    verticalScaleFactor: myScaleFactorV
                                                                });
                                            
                                            
                                                            if (myObjectHeight * myScaleFactorH == columnHeight) {
                                                                return null;
                                                            } else if (myObjectHeight * myScaleFactorH < columnHeight) {
                                                                myFound[i].pageItems[0].transform(
                                                                    CoordinateSpaces.INNER_COORDINATES,
                                                                    AnchorPoint.TOP_LEFT_ANCHOR,
                                                                    myScaleMatrixH);
                                                            } else {
                                                                myFound[i].pageItems[0].transform(
                                                                    CoordinateSpaces.INNER_COORDINATES,
                                                                    AnchorPoint.TOP_LEFT_ANCHOR,
                                                                    myScaleMatrixV);
                                                            }
                                                        }
                                                    }
                                            
                                            
                                                    app.findGrepPreferences = app.changeGrepPreferences = null;
                                            
                                            
                                                } else {
                                                    alert("Open a document");
                                                }
                                            }
                                            

                                             

                                            Edit: Oh, and keep everything inline ^^

                                            1 person found this helpful
                                            • 19. Re: Scale all images at once in InDesign
                                              Laubender Adobe Community Professional & MVP

                                              vinny38  wrote

                                               

                                              … So, I modified the script in a way it first look for overset objects, reduce them to 5% (assuming this would be small enough to make them fit in the flow), then, rescale them as described earlier.…

                                              Hi Vinny,

                                              that would be a good strategy if every anchored image in the story should be scaled.

                                              Alas, this is not the case. Only the ones that exceed the text frame bounds.

                                               

                                              Regards,
                                              Uwe

                                              • 20. Re: Scale all images at once in InDesign
                                                Laubender Adobe Community Professional & MVP

                                                Hi Aman,

                                                also check if in the Word document images are cropped!

                                                InDesign will not crop them when importing the doc or docx file.

                                                That's no feature of the import process.

                                                 

                                                Best,
                                                Uwe

                                                • 21. Re: Scale all images at once in InDesign
                                                  vinny38 Level 5
                                                  • Leaves in-bound images unattended - Image 2 is not rescaled as its size was well under the text frame size

                                                  9.png

                                                  Laubender

                                                   

                                                  you are absolutely right (as usual)... I missed the above part.

                                                   

                                                  I guess changing inline to custom positioning is maybe a very clever idea after all ^^

                                                  Maybe use the script to do that at first, then check dimensions, rescale if necessary, and finally revert back to inline-position.

                                                  Something like this maybe : (not fully tested)

                                                   

                                                  //FitAnchorToColumn v5
                                                  //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,
                                                              myFound;
                                                  
                                                  
                                                          app.findObjectPreferences = null;
                                                          app.findObjectPreferences.anchoredPosition = AnchorPosition.INLINE_POSITION;
                                                          myFound = myDoc.findObject();
                                                  
                                                  
                                                          for (i = 0; i < myFound.length; i++) {
                                                  
                                                  
                                                              // change everything to custom position
                                                              myFound[i].anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;
                                                  
                                                  
                                                              var
                                                                  columnWidth = myFound[i].parent.parentTextFrames[0].textFramePreferences.textColumnFixedWidth,
                                                                  columnHeight = myFound[i].parent.parentTextFrames[0].geometricBounds[2] - myFound[i].parent.parentTextFrames[0].geometricBounds[0],
                                                                  myObjectWidth = myFound[i].geometricBounds[3] - myFound[i].geometricBounds[1],
                                                                  myObjectHeight = myFound[i].geometricBounds[2] - myFound[i].geometricBounds[0],
                                                                  myScaleFactorH = columnWidth / myObjectWidth,
                                                                  myScaleFactorV = columnHeight / myObjectHeight,
                                                                  myScaleMatrixH = app.transformationMatrices.add({
                                                                      horizontalScaleFactor: myScaleFactorH,
                                                                      verticalScaleFactor: myScaleFactorH
                                                                  }),
                                                                  myScaleMatrixV = app.transformationMatrices.add({
                                                                      horizontalScaleFactor: myScaleFactorV,
                                                                      verticalScaleFactor: myScaleFactorV
                                                                  });
                                                  
                                                  
                                                              // check dimensions
                                                              if (myObjectWidth > columnWidth && myObjectHeight <= columnHeight) {
                                                                  myFound[i].transform(
                                                                      CoordinateSpaces.INNER_COORDINATES,
                                                                      AnchorPoint.TOP_LEFT_ANCHOR,
                                                                      myScaleMatrixH);
                                                  
                                                  
                                                              } else if (myObjectHeight > columnHeight) {
                                                                  myFound[i].transform(
                                                                      CoordinateSpaces.INNER_COORDINATES,
                                                                      AnchorPoint.TOP_LEFT_ANCHOR,
                                                                      myScaleMatrixV);
                                                              } else {
                                                                  // nothing happens;
                                                              }
                                                  
                                                  
                                                              // change back to inline  position
                                                              myFound[i].anchoredObjectSettings.anchoredPosition = AnchorPosition.INLINE_POSITION;
                                                          }
                                                  
                                                  
                                                  
                                                  
                                                      } else {
                                                          alert("Open a document");
                                                      }
                                                  }
                                                  
                                                  • 22. Re: Scale all images at once in InDesign
                                                    Laubender Adobe Community Professional & MVP

                                                    Hi Vinny,

                                                    I hope you also noticed this other thread running in the InDesign Scripting forum that is tackling the same problem:

                                                    Scale all images at once in InDesign

                                                     

                                                    Here Marc Autret's recent attempt to solve the problem in the same thread:

                                                    Re: Scale all images at once in InDesign

                                                     

                                                    Regards,
                                                    Uwe

                                                    • 23. Re: Scale all images at once in InDesign
                                                      vinny38 Level 5

                                                      Hi Uwe...

                                                      Marc Autret, Peter Kahrel, and... yourself are on the case?!

                                                      Lucky Aman Problem should be solved in the blink of an eye then.

                                                      So I leave this to the experts.

                                                      I would just love to have amanm5143 feedback on latest version (v5) and see if it works as expected.

                                                      Regards

                                                      Vinny

                                                      • 24. Re: Scale all images at once in InDesign
                                                        Laubender Adobe Community Professional & MVP

                                                        Hi Vinny,

                                                        at times I'm only a bystander throwing some ideas in here and there.

                                                        Let's see what Aman is telling after testing your latest piece of code.

                                                         

                                                        Best,
                                                        Uwe

                                                        • 25. Re: Scale all images at once in InDesign
                                                          amanm5143 Level 1

                                                          Hi,

                                                          Firstly, a big thank you to both - vinny38 and Laubender for dedicating their valuable time to the query. I am truly lucky to have been supported by you guys.

                                                          Laubender: As per your suggestion, I did check out the mages in the word document and they appear to be normal (not cropped).

                                                          vinny38: Though experts have shown a kind gesture of looping in and providing valuable inputs but you have been the torch bearer and main lead for this query. Your solution and zeal provided the necessary break-through, so I urge you to take it to the finish line, as well. Your indulgence and dedication towards the puzzle enticed others to take an interest. So, request you to not leave us hanging, now when you have almost solved the puzzle. Once it is done, the whole community will be grateful to you because this is one of the problems which has been faced by every user, atleast once.

                                                          I tried both versions of the script and, below are the notes:

                                                          Version 4:

                                                          Version 4 worked perfectly for few images.

                                                          Below image was out of bounds in terms of "width and not height". So, the script perfectly rescaled the image under text frame size.

                                                          13.PNG

                                                          However, for very large images, it followed the script's approach of rescaling by a factor of 5%. The small cross was a large image which was out of bound on both ends - width as well as height. Though this is a minor issue, as one can change the scale factor to make the necessary adjustment.

                                                          14.PNG

                                                          Major point of concern in Version 4 was that the script re-scaled the in-bound images as well (those which were well under the text frame size) leading to loss of pixel density in case of small images and major underscaling (5%), in case of normal sized images.

                                                           

                                                          Your script definitely solved the problem of overflow as the whole text flowed perfectly. This is major breakthrough. I repeat, a major one. This is gonna help in creating a simpler workflow for many users. Big Thank You!!!1

                                                           

                                                          I guess, you tried to tackle the issue with version 5 which may leave in-bound images, unattended.

                                                          Version 5:

                                                          Whenever I try to run the script, it gives the following error:

                                                          15.PNG

                                                          I checked for Anchor Positioning as well and it was fine. So, I am not able to figure out the cause of the error.

                                                          Regards,

                                                          Aman

                                                          • 26. Re: Scale all images at once in InDesign
                                                            Marc Autret Level 5

                                                            Hi Uwe,

                                                             

                                                            Thanks—I didn't notice there was a competing thread on the same topic. So by joining forces we should succeed ;-)

                                                             

                                                            Best,

                                                            Marc

                                                            • 27. Re: Scale all images at once in InDesign
                                                              vinny38 Level 5

                                                              Hi Aman

                                                              Hard to tell what's returning the error... (Working here...)

                                                              Did you copy correctly the entire javascript?

                                                              Or maybe the order of the instructions were not right after all...

                                                               

                                                              I doubt it will fix the issue, but please try this version 6, slightly modified:

                                                               

                                                              //FitAnchorToColumn v6 
                                                              //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,
                                                                          myFound;
                                                              
                                                              
                                                                      app.findObjectPreferences = null;
                                                                      app.findObjectPreferences.anchoredPosition = AnchorPosition.INLINE_POSITION;
                                                                      app.findChangeObjectOptions.objectType = ObjectTypes.GRAPHIC_FRAMES_TYPE;
                                                                      myFound = myDoc.findObject();
                                                              
                                                              
                                                                      // change everything to custom position  
                                                                      for (i = 0; i < myFound.length; i++) {
                                                                          myFound[i].anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;
                                                                      }
                                                                      //then check and transform
                                                                      for (i = 0; i < myFound.length; i++) {
                                                                          var
                                                                              columnWidth = myFound[i].parent.parentTextFrames[0].textFramePreferences.textColumnFixedWidth,
                                                                              columnHeight = myFound[i].parent.parentTextFrames[0].geometricBounds[2] - myFound[i].parent.parentTextFrames[0].geometricBounds[0],
                                                                              myObjectWidth = myFound[i].geometricBounds[3] - myFound[i].geometricBounds[1],
                                                                              myObjectHeight = myFound[i].geometricBounds[2] - myFound[i].geometricBounds[0],
                                                                              myScaleFactorH = columnWidth / myObjectWidth,
                                                                              myScaleFactorV = columnHeight / myObjectHeight,
                                                                              myScaleMatrixH = app.transformationMatrices.add({
                                                                                  horizontalScaleFactor: myScaleFactorH,
                                                                                  verticalScaleFactor: myScaleFactorH
                                                                              }),
                                                                              myScaleMatrixV = app.transformationMatrices.add({
                                                                                  horizontalScaleFactor: myScaleFactorV,
                                                                                  verticalScaleFactor: myScaleFactorV
                                                                              });
                                                              
                                                              
                                                                          if (myObjectWidth > columnWidth && myObjectHeight <= columnHeight) {
                                                                              myFound[i].transform(
                                                                                  CoordinateSpaces.INNER_COORDINATES,
                                                                                  AnchorPoint.TOP_LEFT_ANCHOR,
                                                                                  myScaleMatrixH);
                                                              
                                                              
                                                                          } else if (myObjectHeight > columnHeight) {
                                                                              myFound[i].transform(
                                                                                  CoordinateSpaces.INNER_COORDINATES,
                                                                                  AnchorPoint.TOP_LEFT_ANCHOR,
                                                                                  myScaleMatrixV);
                                                              
                                                              
                                                                          } else {
                                                                              // nothing happens;  
                                                                          }
                                                                      }
                                                              
                                                              
                                                                      // change back to inline  position  
                                                                      for (i = 0; i < myFound.length; i++) {
                                                                          myFound[i].anchoredObjectSettings.anchoredPosition = AnchorPosition.INLINE_POSITION;
                                                                      }
                                                                  
                                                                  } else {
                                                                      alert("Open a document");
                                                                  }
                                                              }
                                                              

                                                               

                                                              Now, if you still have a javascript error, which is most likely to be the case, please remove line 3, 5 and 6 so that :

                                                               

                                                              if (parseFloat(app.version) < 6)
                                                                  main();
                                                              else
                                                                  app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "FitAnchorToColumn");
                                                              

                                                              Turns to

                                                              main();
                                                              

                                                               

                                                              Run the script again and please report back the new javascript error, which will hopefully tell us more...

                                                               

                                                              Please note that I won't be available till Thursday to try to fix the issue, but probably others will help...

                                                              Regards

                                                              Vinny