4 Replies Latest reply on Jul 12, 2009 8:46 PM by Dave Saunders

    StoryOffset Page Number


      Using StoryOffset of XmlElement or PI is it possible to get the Page Number?




        • 1. Re: StoryOffset Page Number
          Thomas B. Nielsen Level 3

          var myPageItem = app.activeDocument.pages[0].pageItems[0];
          var myPage = findPage(myPageItem);


          // for page number either use
          var myPageNum = myPage.name;


          // or
          var myPageNum2 = myPage.documentOffset;


          // findPage by Dave Saunders
          function findPage(theObj) {
              var thePage = theObj;
              if (thePage.hasOwnProperty("baseline")) {
                thePage = thePage.parentTextFrames[0];
              while (thePage.constructor.name != "Page") {
                var whatIsIt = thePage.constructor.name;
                switch (whatIsIt) {
                  case "Story" :
                    thePage = thePage.textFrames[-1].parent;
                  case  "Character" :
                    thePage = thePage.parentTextFrames[0];
                  case "Cell" :
                    try {
                      thePage = thePage.insertionPoints[0].parentTextFrames[0];
                    } catch (e) {
                      // must be overset, so ignore
                      return null;
                  case "Application" :
                    // must be off page, so ignore
                    return null;
                thePage = thePage.parent;
              return thePage

          • 2. Re: StoryOffset Page Number
            Dave Saunders Level 4

            This is the latest version of the findPage function that I currently use:


            function findPage(theObj) {

            if (theObj.hasOwnProperty("baseline")) {

            theObj = theObj.parentTextFrames[0];


            while (theObj != null) {

            var whatIsIt = theObj.constructor;

            switch (whatIsIt) {

            case Page : return theObj;

            case Character : theObj = theObj.parentTextFrames[0]; break;

            case Footnote :; case Cell : theObj = theObj.insertionPoints[0].parentTextFrames[0]; break;

            case Note : ; case Footnote : theObj = theObj.storyOffset; break;

            case Application : return null;


            if (theObj == null) return null;

            theObj = theObj.parent;


            return theObj

            } // end findPage


            Bear in mind when calling it that you might get a null return.



            • 3. Re: StoryOffset Page Number
              Harbs. Level 6



              Something's wrong there...


              You have "case Footnote" in there twice.



              • 4. Re: StoryOffset Page Number
                Dave Saunders Level 4

                Ooh! So I do. Well, the first one's right so I guess that is the one that was used when I ran this just the other day in a script that was dealing with split footnotes!


                The second instance tells you which page the footnote reference is on but that doesn't help if you're dealing with text in a footnote that flows on to another page and you want to know which page that is.