4 Replies Latest reply on Oct 24, 2012 11:39 AM by Jump_Over

    Placing image as text fill


      Im quite new to Indesign scripting (but not JS) and have been struggling with this one for days.


      The Problem:


      Create some text (could be single word, multiline or on a path) = DONE

      Convert the text to outlines = DONE

      Fill the new outlines with an image = FAIL!


      Well thats not exactly true.

      Ive managed to place an image into converted text but it repeatedly does it for each line of text rather than placing inside the whole selection. When I look at the converted text I can see it creates a compound path for each line of text and therefore places the image inside each one (had to create a loop to do it). However I know this is wrong.


      What I THINK it should do is combine the newly created compound paths into one BEFORE placing the image but everything Ive tried just wont work.


      Is there anyone out there that can give some assistance before I pull my hair out?



        • 1. Re: Placing image as text fill
          Jump_Over Level 5



          To outline text means: each line of text becomes a polygon object (path).

          So text.createOutline method gives you grouped polygons (group.lenght = count of lines).


          You need to ungroup this and from this point:


          MP = app.activeDocument.polygons;     // to be straight it is a new (almost) empty doc

          myFinalPath = MP[0].makeCompoundPath(MP.itemByRange(1,-1) )     // first polygon composed with the rest


          myFinalPath should be ready to plase an image into



          • 2. Re: Placing image as text fill
            w0rkhorse Level 1

            Thanks for that, it worked a treat.


            HOWEVER, I've just realised it wont work for text on a path. Im assuming its because text on a path is not in a textframe which is what its currently looking for.


            Heres what I have now...


            var doc = app.activeDocument;

            var textFrames = doc.textFrames.everyItem().getElements();




                      for (var i=0; i< textFrames.length; i++) {





                      // DO SOMETHING FOR TEXT ON A PATH



            MP = app.activeDocument.polygons;

            myFinalPath = MP[0].makeCompoundPath(MP.itemByRange(1,-1) )  



            myFinalPath.place(File("/Users/Public/Pictures/Sample Pictures/Lighthouse.jpg"));



            Any ideas will be greatly appreciated.

            • 3. Re: Placing image as text fill
              Jump_Over Level 5



              First, your doc looks much more complex I suspected, so be careful with this code to avoid unwanted effects  - it was just an example.


              Second, text on path isn't in textFrame indeed. Its container is a textPath and its parent could be a rectangle, oval, graphicLine, polygon, etc.


              Third, any of above has createOutlines() method available.

              As far as I know, you could do it using, i.e. polygon.textPath[0].parentStory.createOutline()

              but things are going to be complicated here.


              At this point we need a help from someone wiser then I am trying to be

              • 4. Re: Placing image as text fill
                Jump_Over Level 5


                If on your document's 1st page are some textFrames and some paths (a line, rectangle, polygon) and:

                - text is inside textFrames or

                - text is aligned on path and

                - those texts supposed to be converted to outlines and

                - there are not other polygons then those created from texts and

                - all outlines created suppose to be one compound path ready to place image into


                a solution could be like this:



                var page = app.activeDocument.pages[0];

                var PItems = page.allPageItems;

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

                     if (PItems[i].textPaths.length > 0)

                          PItems[i].contentType = ContentType.TEXT_TYPE;   // here each textPath parent is converted into textFrame


                var textFrames = page.textFrames.everyItem().getElements();


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




                MP = app.activeDocument.polygons;

                switch (MP.length) {

                     case 0: {alert ("Zero outlines created"); exit();}

                     case 1: {myFinalPath = MP[0]; break;}

                     default: {myFinalPath = MP[0].makeCompoundPath(MP.itemByRange(1,-1) );



                myFinalPath.place(File("/c/Users/Public/Pictures/Sample Pictures/Lighthouse.jpg"));