2 Replies Latest reply on Jun 7, 2016 4:14 AM by JustOneBren

    Odd and Even Page Identification

    JustOneBren Level 1

      If possible I am in need of some help please,


      Here is a simplified script to show the basics, if solved I will adjust it to work to a full script.

      This script is totally inadequate but I have no idea how to get it to work, if the page is odd then alert "Odd Page", and if even then alert "Even Page".


      pgNum = app.activeDocument.sections[0].pageNumberStart

      if (pgNum==1) {alert ("Odd Page")};

      else if (pgNum==2) {alert ("Even Page")};


      This needs to run on Single Pages (i.e. not Facing Pages) so cannot use the "PageSideOptions.RIGHT_HAND" or "PageSideOptions.LEFT_HAND".


      Many Thanks for any help, Brendan

        • 1. Re: Odd and Even Page Identification
          Marc Autret Level 4

          Hi Brendan,


          According to the doc the property Section.pageNumberStart is "valid only when continue numbering is false," so you should rely on Section.pageStart instead.


          Now given a Page, you have two useful properties,

          • Page.name is a string that reflects the name of the page, which usually means the page number (but this depends on Section.pageNumberStyle.)
          • Page.documentOffset is the sequential index of the page within the document (while Page.index is the index within the spread, not relevant here.)


          Assuming that Page.name is ok for your project, you just have to parse it as a number then to check whether pgNum % 2 is 0 or 1.


          var pg = app.activeDocument.sections[0].pageStart,
              pgNum = parseInt(pg.name,10),
          if( isNaN(pgNum) )
              alert( "Page name can't be parsed as an integer." )
              side = (pgNum%2) ? "Odd " : "Even ";
              alert( side + " Page" );




          • 2. Re: Odd and Even Page Identification
            JustOneBren Level 1

            The Page.name is perfectly adequate and your script has worked like a dream, still a beginner in scripting so the explanation is very helpful too.


            Many thanks for taking the time, Brendan