7 Replies Latest reply on Aug 30, 2009 11:21 PM by Harbs.

    Is there a script that will convert auto-page numbers into regular text (for an xml export)?

    marykulp

      I've got a 500 page catalog that I've tagged in detail to be parsed and loaded into a database. Everything is just fine, except now the client wants page refs to the printed catalog in the database also. Since page numbers are "special characters" they don't come out in my export. Can anyone recommend a way (maybe a script) that will convert my page numbers to regular text?

       

      Thanks kindly,

      Mary

        • 1. Re: Is there a script that will convert auto-page numbers into regular text (for an xml export)?
          Harbs. Level 6

          This should do it:

           

          ResetFindPrefs();
          app.findGrepPreferences.findWhat = "~N";
          var finds = app.documents[0].findGrep();
          for (var i=finds.length-1;i>=0;i++){
              var page = FindWhere(finds[i]);
              var section = page.appliedSection;
              if(section.includeSectionPrefix){
                  var prefix = section.sectionPrefix;
              } else {
                  var prefix = "";
              }
              finds[i].contents = prefix+page[i].name;
          }
          
          function ResetFindPrefs(){
            app.findTextPreferences = null;ResetFindChangeOptions();
          }
              //**********************************
          function ResetFindChangeOptions (){
              app.findChangeTextOptions.properties = app.findChangeGrepOptions.properties = {
                  includeLockedStoriesForFind:false,
                  includeLockedLayersForFind:false,
                  includeHiddenLayers:false,
                  includeMasterPages:false,
                  includeFootnotes:false,
                  wholeWord:false,
                  caseSensitive:false
              }
          }
          
          function FindWhere (obj, where){
              var getTextContainer = function (s){
                  if(kAppVersion<5){return s.textFrames[-1]}else{return s.textContainers[s.textContainers.length-1]}
                  }
              var getobj = function (fm){//returns the parent text frame, or the last one of the parnet story
                  if(fm != undefined){return fm;}else{return getTextContainer(obj.parentStory);}
                  }
              var getobj_ptf  = function (obj){//get the parent text frame or return the original object (necessary for Notes)
                  try{ return obj.parentTextFrames[0]}catch(e){return obj}
                  }
              var getobj_cell = function (fm){//returns the parent text frame, or the last one of the parnet story -- for cells
                  if(fm != undefined){return fm;}else{return getTextContainer(obj.insertionPoints[0].parentStory);}
                  }
              var getnote_tf = function (note){//gets the note location for both footnotes and notes in all versions...
                  if(kAppVersion<5){
                      if(note.hasOwnProperty("footnoteTextFrame")){var parentFrame = note.footnoteTextFrame}//no good for overset...
                      else{var parentFrame = note.parentTextFrame}
                      if(parentFrame){return parentFrame}
                      else{return note.parent}
                      }
                  else{return note.storyOffset}
                  }
              kAppVersion=parseFloat(app.version);
              var e;
              if(!obj){return null}
              if(where == undefined){var where = Page;}
              if(obj.hasOwnProperty("baseline")){obj = getobj(getobj_ptf (obj))}
              while(obj){
                  switch(obj.constructor){
                      case where: return obj;
                      case Story: obj = getTextContainer(obj);break;
                      case Character: obj = getobj(getobj_ptf (obj));break;
                      case Cell: obj = getobj_cell(getobj_ptf(obj.insertionPoints[0]));break;
                      case Note:
                      case Footnote: obj = getnote_tf(obj);break;
                      case Application: return null;
                      }
                  if (!obj) return null; 
                  obj = obj.parent;
                  }
              return null;
              }
          
          1 person found this helpful
          • 2. Re: Is there a script that will convert auto-page numbers into regular text (for an xml export)?
            marykulp Level 1

            Thanks very much Harbs.

             

            I'm having a problem with this line

             

            finds[i].contents = prefix+page[i].name

             

            "Object does not support property or method '25'"

             

            Any ideas?

            • 3. Re: Is there a script that will convert auto-page numbers into regular text (for an xml export)?
              [Jongware] Most Valuable Participant

              Hey, Harbs is on the case!

               

              (Note how he uses

               

              var finds = app.documents[0].findGrep();
              for (var i=finds.length-1;i>=0;i++)

               

              -- findGrep also has the 'return reversed' flag -- but this'll work, this'll work...)

               

              You are getting the error because of Javascript's little idiosyncracy in handling numbers and strings. JS tries to be indifferent about them, converting to and fro' where necessary, unnoticeable to the user, but this is one of the cases where it gets confused. Both "prefix" and "name" are usually strings, but I'm guessing "prefix" is empty (he thoughtfully included the "Page prefix" from the "Page and Section Numbering" dialog in case you used it) and the page "name" consist of digits only. That makes JS think this is "(nothing) + (a number)", which -- still correctly -- yields a number. "finds[i].contents", on the other hand, only expects a string. Confusion galore!

               

              Manually overriding the name to be a string will solve it:

               

              finds[i].contents = prefix+String(page[i].name);
              • 4. Re: Is there a script that will convert auto-page numbers into regular text (for an xml export)?
                marykulp Level 1

                haha. 2 threads.

                 

                Harbs. an alternate conversation about this issue is at http://forums.adobe.com/message/2214061#2214061.

                 

                good times. as I mentioned to Jongware in the other thread, I am a bit overextended at the moment and will have to revisit this early AM.

                • 5. Re: Is there a script that will convert auto-page numbers into regular text (for an xml export)?
                  Harbs. Level 6

                  Yeah, I missed the other thread.

                   

                  I didn't test this before posting. Just pecked away...

                   

                  Besides the String error, there's also an error in the loop.

                   

                  Instead of:

                   

                  for (var i=finds.length-1;i>=0;i++){

                  It should have been:

                  for (var i=finds.length-1;i>=0;i--){
                  • 6. Re: Is there a script that will convert auto-page numbers into regular text (for an xml export)?
                    [Jongware] Most Valuable Participant

                    (cough) "but this'll work, this'll work.." No, this won't work, this won't work...

                     

                    H., findGrep also comes with that 'reverse' parameter, which makes these loops just a bit easier to read and less error prone.

                    • 7. Re: Is there a script that will convert auto-page numbers into regular text (for an xml export)?
                      Harbs. Level 6

                      Yes. I know there is the reverse parameter. I prefer to use a reverse 

                      loop because I like to be able to easily see in the code which way the 

                      loop is working. Besides a reverse loop is ever so slightly more 

                      efficient...

                       

                      I never really understood why they created the "reverse" parameter at 

                      all. If you want the results to be reversed it's easy enough to do 

                      with finds.reverse().

                       

                      Harbs