2 Replies Latest reply on Sep 14, 2010 1:53 PM by Harbs.

    Differences in Paragraph/Text Style Ranges in CS3/4

    pjaromin Level 1

      I have code that exports the text from a frame into "block" and "inline" element. The code written for CS3 looks something like this below:

       

       

      var doc = app.activeDocument;

      var pageItems = doc.pageItems;

      for (var i = 0; i < pageItems.count(); i++) {

        var pageItem = pageItems.item(i);

        var textFrame = pageItem;

        $.writeln("Number of Paragraphs: " + textFrame.paragraphs.count());

        for (var j = 0; j < textFrame.paragraphs.count(); j++) {

          handleParagraph(textFrame.paragraphs.item(j), j);

        }

      }


      function handleParagraph(para, count) {

        if (para.constructor.name == "Story" ) {

          $.writeln("Paragraph is a Story");

       

        }

        else {

          for (var i = 0; i < para.textStyleRanges.count(); i++) {

            var text = para.textStyleRanges.item(i);

            $.writeln("PARAGRAPH[" + (count+1) + "] has text [" + para.contents + "]" );

          }

        }

      }

      '';

       

       

      When you have 2 paragraphs of text that contain a single sentence in the default text format, this outputs something like:

       

       

      Number of Paragraphs: 2

      PARAGRAPH[1] has text [Paragraph 1

      ]

      PARAGRAPH[2] has text [Paragraph 2]

       

      However, when I run the same code against a document in CS4, I get:

       

      Number of Paragraphs: 2

      PARAGRAPH[1] has text [Paragraph 1

      Paragraph 2]

      PARAGRAPH[2] has text [Paragraph 2]

       

      So the contents of the first text range in paragraph #1 under CS3 stops at the end of paragraph 1, while in CS4, it contains ALL of the contents of the frame (that is of the same style). The content of paragraph #2 starts with the text in paragraph #2.
      Is there a "correct" method for doing what I'm attempting here? Or at least some way of accomplishing this that should work in BOTH CS3 and CS4 (and CS5 as well I suppose)?
      Thanks!
      -Patrick