6 Replies Latest reply on Jun 25, 2010 3:48 AM by PankChat

    adding formatted text in frame

    Gerd2

      Hi,

      im trying to add text with differents formatting styles (e.g. font, size, color) which is not seperated by a space:

       

      An example:

       

      // "frame" is a given textframe

      frame.parentStory.insertionPoints.item(-1).contents = "text1";

      frame.parentStory.words.lastItem().appliedFont= "Arial";

      frame.parentStory.words.lastItem().pointSize = 10";


      frame.parentStory.insertionPoints.item(-1).contents = "text2";

      frame.parentStory.words.lastItem().appliedFont= "Times New Roman";

      frame.parentStory.words.lastItem().pointSize = 12";

       

      After this, "text1text2" is formatted in "Times New Roman., 12Pts".

      I tried to seperate "text1" and "text2" with "SpecialCharacters.hairSpace", but this did not help.

       

      Have someone an idea?

       

      Thanks!!

        • 1. Re: adding formatted text in frame
          [Jongware] Most Valuable Participant

          Use character ranges rather than words:

           

          frame.parentStory.insertionPoints.item(-1).contents = "text1";
          frame.parentStory.words.lastItem().appliedFont= "Arial";
          frame.parentStory.words.lastItem().pointSize = 10;
          endIndex = frame.parentStory.characters.item(-1).index;
          frame.parentStory.insertionPoints.item(-1).contents = "text2";
          frame.parentStory.characters.itemByRange(endIndex+1, frame.parentStory.characters.item(-1).index).appliedFont= "Times New Roman";
          frame.parentStory.characters.itemByRange(endIndex+1, frame.parentStory.characters.item(-1).index).pointSize = 12;
          

           

          .. although in this case it's easier to first change the formatting of the last insertion point and then insert the text:

           

          frame.parentStory.insertionPoints.item(-1).appliedFont= "Arial";
          frame.parentStory.insertionPoints.item(-1).pointSize = 10;
          frame.parentStory.insertionPoints.item(-1).contents = "text1";
          
          frame.parentStory.insertionPoints.item(-1).appliedFont= "Times New Roman";
          frame.parentStory.insertionPoints.item(-1).pointSize = 12;
          frame.parentStory.insertionPoints.item(-1).contents = "text2";
          
          • 2. Re: adding formatted text in frame
            Marc Autret Level 4

            Try this:

             

            var ips = frame.parentStory.insertionPoints;
            ips.item(-1).properties = {
                 appliedFont: 'Arial',
                 pointSize: 10,
                 contents: "text1"
                 };
            ips.item(-1).properties = {
                 appliedFont: 'Times New Roman',
                 pointSize: 12,
                 contents: "text2"
                 };
            

             

            @+

            Marc

             

            [EDIT] Oups! Jongware was the first... as usual! ;-)

            1 person found this helpful
            • 3. Re: adding formatted text in frame
              Gerd2 Level 1

              Thank you Marc and Jongware, now it works fine!

              • 4. Re: adding formatted text in frame
                PankChat Level 1

                I've similar kind of situation though in my case the order gets changed.

                 

                I am inserting some special marked text on top of each page. The frames

                are threaded though. For instance I iterate my document's  each page twice

                to insert a special marker, Something like below:

                 

                 

                1st go (Iterate all pages one by one)

                 

                var myText="{\some text\}";

                myDoc.pages[1].textFrames.itemByName("threaded").insertionPoints.item(0).properties

                = ;

                 

                2nd go(Iterate all pages again one by one)

                var myText="{\some_other_text\}";

                myDoc.pages[1].textFrames.itemByName("threaded").insertionPoints.item(0).properties

                = ;

                 

                Ideally I am expecting

                 

                {\some text\}{\some_other_text\}

                 

                But I get

                 

                {\some_other_text\}{\some text\}

                 

                I think I need to use itemByRange to find out the "\}" or might be end of

                the first word for 2nd go

                 

                Any ideas.

                 

                Best,

                --PC

                • 5. Re: adding formatted text in frame
                  Marijan Tompa [tomaxxi] Level 4

                  Hey!

                   

                  Try changing item(0) to item(-1)

                   

                  tomaxxi

                  • 6. Re: adding formatted text in frame
                    PankChat Level 1

                    Well I need to add marked text on top of story/page.

                     

                    I rather need the END index of first word of text frame to to insert the

                    second marker after it.

                     

                    {\sometext}FIND THE INDEX VALUE OF END OF WORD

                    and add second marker.

                     

                    myDoc.pages[i].textFrames.itemByName("sections").words.firstItem().index