5 Replies Latest reply on Dec 30, 2014 9:58 PM by hurix@123

    Image File Name

    hurix@123 Level 1

      Hi

       

      I Need to get link name in newHeights, can any one help me

       

       

       

      newHeights = { 

       

      linkname: 4.4,

        /*  "O1.tif": 4.4, 

          "IMG_1334.jpg": 4.4, 

          "IMG_1335.jpg": 1, 

          /// ... */

      }; 

          

      for (i = 0, l = doc.links.length; i < l; i++) { 

       

       

      var link = doc.links;

      var sourcefile = link[i].filePath;

      alert (sourcefile);

      var linkname = link[i].name;

         

          if (linkname in newHeights) { 

              pageItem = link.parent.parent; 

              height = pageItem.visibleBounds[2] - pageItem.visibleBounds[0]; 

              target = new UnitValue(newHeights[linkname], 'in').as('pt'); 

              scale = target / height; 

              matrix = app.transformationMatrices.add({horizontalScaleFactor: scale, verticalScaleFactor: scale}); 

              pageItem.transform(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.CENTER_ANCHOR, matrix); 

                  } 

        • 1. Re: Image File Name
          -hans- Level 4

          well, if you want to check if a objcet has got a property just check if it is true ...

           

          if(newHeights.hasOwnProperty('linkname'))...

           

          Your attempt: linkname in newHeights is a setup for a loop ...

           

          There'll be many other possibilities ....

          • 2. Re: Image File Name
            hurix@123 Level 1

                    pageItem.transform(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.CENTER_ANCHOR, matrix); 

             

            show error on above line: Unable to set BoundingBox

            • 3. Re: Image File Name
              hurix@123 Level 1

              hans

               

              everything is ok, script run perfectly But problem is

               

              pageItem.transform(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.CENTER_ANCHOR, matrix);

               

              showing cannot set boundingbox.

              • 4. Re: Image File Name
                steverocket2 Level 1

                Hi,

                 

                I have linked a sample PDF document and

                modified your code some. This works for me:

                 

                 

                var doc = app.activeDocument;

                var newHeights = {

                 

                linkname: 4.4,

                "SampleDocument-5.pdf": 4.4

                    /*

                    "IMG_1334.jpg": 4.4,

                    "IMG_1335.jpg": 1,

                    /// ... */

                };

                 

                 

                for (i = 0, l = doc.links.length; i < l; i++) {

                 

                 

                var link = doc.links;

                var sourcefile = link[i].filePath;

                alert (sourcefile);

                var linkname = link[i].name;

                  

                    if (linkname in newHeights) {

                       var curLink = link[i];

                        pageItem = curLink.parent.parent;

                        height = pageItem.visibleBounds[2] - pageItem.visibleBounds[0];

                        target = new UnitValue(newHeights[linkname], 'in').as('pt');

                        scale = target / height;

                        matrix = app.transformationMatrices.add({horizontalScaleFactor: scale, verticalScaleFactor: scale});

                        pageItem.transform(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.CENTER_ANCHOR, matrix);

                            }

                  }

                • 5. Re: Image File Name
                  hurix@123 Level 1

                  Thanks Steve,

                   

                  I have huge images in my document, so i can expect  to get document link name in newHeights.

                   

                  if i give file name "O1.tif" It works.