4 Replies Latest reply on Dec 21, 2010 9:53 AM by KeithGilbert

    [JS CS5] Resizing graphics after importing XML, but before placing on page

    KeithGilbert Level 1

      I've been looking for an answer for this for a long time, and judging by the other posts here, many others are also.


      Given an XML file consisting of:





                     <image href="file:///filepathhere"/>



                     <image href="file:///filepathhere"/>



      I can import this into a layout, and drag the products element to a text frame. All the images appear inline, and then I run a script that uses XML Rules to locate the images, resize the image frames, and apply an object style. The trouble is, that once in a while the images references by the XML are so enormous that they simply exceed the bounds of the pasteboard, and things blow up.


      So what I want to do instead, is to somehow resize the images to a manageable size BEFORE I drag the products element into a text frame.


      Ole posted a possible solution here: http://forums.adobe.com/message/1108974#1108974


      In that post, he says that "If you're using CS4, can use the resize method to resize graphics that have not yet been placed in a layout." I've been trying to implement his "rough" script, and I can't work it out.


      This is what I have:


      var myRuleSet = new Array (new processImage);

      with (myDoc) {

           var elements = xmlElements;

           __processRuleSet(elements.item(0), myRuleSet);


      function ProcessImage(){

           this.name = "ProcessImage";

           this.xpath = "/root/products/product/image";

           this.apply = function(myElement, myRuleProcessor){

                var myImage = myElement.graphics.item();

                myImage.resize(CoordinateSpaces.innerCoordinates, AnchorPoint.centerAnchor, ResizeMethods.multiplyingCurrentDimensionsBy,[.1,.1]);


                return true;




      "myImage" isn't valid in the script above. Does anyone know if this is possible, and if so, what I'm doing wrong? Thanks for any light anyone can shed on this!