4 Replies Latest reply on Nov 25, 2008 2:45 PM by (elearning_developer2)

    determining which page an image is on

      I am trying to replace all the images in a document with a different image. To do this, I am looping through all images in the document, getting the image bounds, determining which page the image is on, then using that information to create a textframe and place a new image. I am using this code to determine which page an image is on:

      pageImageIsOn = myImages[ imgNum ].parent.parent.parentTextFrames[0].parent.name;

      Sometimes, this gives the opposite page - I am not sure if it is giving the opposite page on the spread, or the wrong number because the textframe is linked to the page opposite on the spread.

      The textframes are created dynamically in earlier parts of the script.

      (the reason I am using this approach is that the original images are inserted in xml elements - they are placeholders - the replacement images are placed directly on the page)

      Thank you.
        • 1. Re: determining which page an image is on
          Level 1
          If you have an anchored object that is across the spread from the anchor point, then indeed you'll get the wrong page with your line of code. And, to be quite honest, that's a challenging case to deal with.

          What you could do is set the ruler origin to spread and compare the left coordinate of the object with the left coordinate of the right page to work out which page it is on.

          The spread is, of course, the parent of the page, so you're almost there as far as finding it is concerned.

          • 2. Re: determining which page an image is on
            Level 1
            Thank you - however, after experimentation, I think I need a different approach. Mixed facing pages is not the only obstacle. This is a toughy!

            What I am trying to do is use placeholder images in xml elements (placed during rule processing of an imported xml doc) to mark locations for other images that will be placed in a second pass. These new images will be chosen based on the tag content.

            I cannot place images based on content the first time through because they end up inside the xml element, and so cannot be floated in the margin.

            My first approach involved looping through all images in the document (myDocument.allGraphics) and replacing them based on the content info I recorded in the initial doc processing - this ALMOST works. Unfortunately, they are not exactly in the right order - sometimes, they are a bit off, especially when content spans multiple pages.

            I tried copying the placeholders into an array the first time through - however, the images in this array do not allow access of the page information via the heirarchy above.

            Is there another approach? Thanks again for helping.
            • 3. Re: determining which page an image is on
              Level 1
              The other way to get at all the graphics in a document is to use the Links collection. I'm not sure that this will do you much good though.