1 Reply Latest reply on Sep 10, 2016 2:56 PM by borise78101190

    Append image next to imported XML-content

    borise78101190

      Dear InDesign-Users,

       

      I import some text into an InDesign-Template (basically in one story).

      When I import this XML i do some adjusting with XML-rules, like adding a Headline.

       

      function AddHeading(){

          this.name = "AddHeading";

          this.xpath = "//phoneno[1]";

          this.apply = function(myElement, myRuleProcessor){

              with(myElement){

                  var myPhoneNo = myElement.xmlContent;

                  myElement.xmlContent.insertionPoints[0].contents  = String('Phone numbers \r');

                  myPhoneNo.words[0].appliedParagraphStyle = app.activeDocument.paragraphStyles.item("HeadingPhoneNo");

              }

              return true;

          }

      }

       

      What I have to do is adding an Image (a Telephone-Icon) next to the added Headline ("Phone numbers").

      Because all the content is floating within one story i cannot get relevant geometrical bounds for this paragraph.

       

      Any ideas how to achieve a placement of an image within this context?

       

      Thank you!

        • 1. Re: Append image next to imported XML-content
          borise78101190 Level 1

          Thanks to Peter, here is the approach solving my problem:

          (adopted from pkahrel great help in this thread: Re: place image as anchor object by finding the text...)

           

           

          function AddHeading(){

              this.name = "AddHeading";

              this.xpath = "//phoneno[1]";

              this.apply = function(myElement, myRuleProcessor){

                  with(myElement){

                      var myPhoneNo = myElement.xmlContent;

                      myElement.xmlContent.insertionPoints[0].contents  = String('Phone numbers \r');

                      myPhoneNo.words[0].appliedParagraphStyle =                       app.activeDocument.paragraphStyles.item("HeadingPhoneNo");

                     var anchor = myElement.storyOffset.textFrames.add ();

                     var f = new File('/Users/PATHTOIMAGE/image.png');

                     var gb = [0,0,"10mm","10mm"];

                     var myObjectStyle = app.activeDocument.objectStyles.item ("HeadingPhoneNo");

                     anchor.appliedObjectStyle = myObjectStyle;

                     anchor.contents = myElement.contents;

                     anchor.geometricBounds = gb;

                     anchor.place(f);

                     anchor.fit (FitOptions.CONTENT_TO_FRAME);

                      }

                      return true;

                      }

                  }