7 Replies Latest reply on Mar 26, 2015 9:15 PM by Vimala lakshmanan

    How to fit the images within textframe in indesign using javascript?

    Vimala lakshmanan Level 1

      Hi,

       

      We are using the update script for updating the values in table.

      If i am using images within textframe, the table is not fitting after updating it. Without using images the table is fitting.

       

      First i have dragged the table in Indesign document. Then i have altered the image size and updated the table using Update script.

      Finally i want to fit the table with the resized images.

       

      Note: I can get the updated values in table . but i cannot get the resized images.( Now i can get the original image after updating the table)

       

      Please help me if anyone has idea regarding this issue.

       

      Thanks,

      Vimala L

        • 1. Re: How to fit the images within textframe in indesign using javascript?
          tanujad54435002 Level 1

          Hi,

           

          I didn't get your question clearly. The image and tables are within the textframe or the textframe consist of table and the table consist of image.

          • 2. Re: How to fit the images within textframe in indesign using javascript?
            Vimala lakshmanan Level 1

            Hi,

             

            The textframe consist of table and the table consist of image.




            • 3. Re: How to fit the images within textframe in indesign using javascript?
              Peter Kahrel Adobe Community Professional & MVP

              > We are using the update script

               

              Which script is that?

               

              Did you try myTextFrame.fit (FitOptions.CONTENT_TO_FRAME); ?

               

              Alternatively, if you use CS6 or later, you can use the Auto-Size options in the Text Frame Options dialog to have the frame size automatically to its content.

               

              Peter

              • 4. Re: How to fit the images within textframe in indesign using javascript?
                Laubender Adobe Community Professional & MVP

                @Peter – if I get the OP right, we have a table cell and an image anchored to one of the insertion points of the texts object of that cell.

                And the container should get the size of the table cell. Or the table cell should be sized after the image's dimensions? (I'm not sure about that).

                 

                So we need to know:

                1. The width of the cell

                2. The height of the cell

                3. All four inset values*

                4. All four stroke widths

                5. The x position of the insertion point of the anchor

                6. The y position of the insertion point of the anchor (maybe the formatting of the baseline shift as well)

                7. The table cell's:
                7.1 autoGrow value
                7.2 rotationAngle value

                7.3 writingDirection

                8. Decide, if would best inline anchor, above line anchor or anchored anchor (;-)) the image

                 

                * maybe we do not need 3.), if we get 5.) and 6.) right and 7.2) and 7.3) is without surprises

                 

                I would suggest to use AnchorPosition.ANCHORED to do that smooth and not let the cell interfer much with the image container's dimensions.

                 

                Also needed:
                A. Stroke weight of the container of the image

                B. Stroke alignment of the container of the image

                 

                Did I forget something?

                 

                Uwe

                • 5. Re: How to fit the images within textframe in indesign using javascript?
                  Laubender Adobe Community Professional & MVP

                  Yes. Of course we need the size of the image and its container ;-)

                   

                  Uwe

                  • 6. Re: How to fit the images within textframe in indesign using javascript?
                    Laubender Adobe Community Professional & MVP

                    Oh. And one or some screenshots could help…

                     

                    Uwe

                    • 7. Re: How to fit the images within textframe in indesign using javascript?
                      Vimala lakshmanan Level 1

                      Hi,

                       

                      Please find below the Update Script,

                       

                      var myDocument = app.activeDocument;

                      var updateOption = app.scriptArgs.get("updateOption");

                      main();

                      function main()

                      {

                      if(updateOption=="UPDATE")

                        {

                        UpdateLink();

                        }

                      }

                      function UpdateLink()

                      {

                      myDoc = app.activeDocument;

                      myLinks = myDoc.links;

                      for (j = myLinks.length - 1; j >= 0; j--)

                      myName = myLinks[j].filePath;

                        var ext =  myName.substring(myName.length-3,myName.length) ;

                      if (myLinks[j].status == LinkStatus.linkOutOfDate)

                      myLinks[j].update();

                      }

                      }

                      }

                       

                      After running this script i cannot get the image in table.

                       

                      While running the Fitting script followed by Update script i am getting the Original size of the image. But i want the re-sized image in table.

                       

                      Fitting Script:

                       

                      var textFitoption= app.scriptArgs.get("textFitOption");

                      var imageFitoption= app.scriptArgs.get("imageFitOption");

                      var tableFitoption= app.scriptArgs.get("tableFitOption");

                      main();

                      function main()

                      {

                        IterateDocument();

                      }

                       

                      function IterateDocument()

                      {

                        for(myCounter = 0; myCounter < app.activeDocument.activeLayer.textFrames.length; myCounter++)

                        {

                        myStory = app.activeDocument.activeLayer.textFrames.item(myCounter);

                        FitPageItem (myStory);

                        }

                      }

                      function FitPageItem (mySel)

                      {

                        if(mySel.associatedXMLElement!=null)

                        {

                      if (mySel.constructor.name == "TextFrame")

                        {

                        if(mySel.associatedXMLElement.xmlAttributes.itemByName("IMAGE_FILE")==null)

                        {

                      mySel.parentStory.clearOverrides();

                        mySel.parentStory.appliedCharacterStyle = app.activeDocument.characterStyles.add()

                        mySel.parentStory.appliedCharacterStyle.remove();

                       

                      //Fit all inline Items

                        graphicItems = mySel.allGraphics;             // I cannot get the graphicItems.

                        for(g=0;g<graphicItems.length;g++)

                        {

                        if(imageFitoption=="Fit Frame To Content")

                        {

                        graphicItems[g].fit(FitOptions.frameToContent);

                        }

                        else if(imageFitoption=="Fit Content Proportionally")

                        {

                        graphicItems[g].fit(FitOptions.proportionally);

                        }

                        }//for

                        }//Has image_file attr

                        }//is text frame

                       

                         if(mySel.associatedXMLElement.markupTag.name=="products")

                        {

                        if(IsImageEmbeddedInTable(mySel)==true)

                        {

                        xmlElem = mySel.associatedXMLElement;

                        mySel.placeXML(xmlElem);

                        }

                        }//if products

                       

                      function IsImageEmbeddedInTable(mySel)

                      {

                        for( var j = 0; j< mySel.tables.length ; j++ )

                        {

                        table = mySel.tables[j];

                        for( var i = 0 ; i< table.cells.length ;i++ )

                        {

                        cell= table.cells[i];

                        cellElement = cell.associatedXMLElement;

                        if(cellElement !=null)

                        {

                        if(cellElement.xmlElements!=null)

                        {

                        if(cellElement.xmlElements.count()>0)

                        {

                        if(cellElement.xmlElements[0].xmlAttributes.itemByName("href")!=null)

                        {

                        return true;

                        }  }  }  }  }  }

                      }

                       

                       

                      Thanks,

                      Vimala L