3 Replies Latest reply on Jul 26, 2014 3:30 PM by HarveyLiu

    How to write a script for report the page number in a book?

    HarveyLiu Level 1

      Hi,

       

      Is that possible to write a script for report the page number in a book by pop up a text file.

       

      What I try to say:

       

      first I open an indesign book, thenI run the script, the script can gen a text file by pop up window, and the file list the file names and the page numbers (only the star number of each file), and the script can also tells me that I have two files or more overlap the page numbers (if any).

       

      sample:

       

       

      book3.jpg

       

       

       

      report like this:

       

      01 Contents                                    1
      02 Summary                                  2
      03 Financial highlight                    3
      04 Chairman's statement              4
      05 MD and A                                 7
      06 CG report                                 12
      07 Directors' report                       17
      08 Auditor's report                        18
      09 Income statement                    19
      10 Profit and loss                          20
      11 Equity change                          20
      12 Cash flow statement                21
      13 Notes to account                     22
      14 Corporate Information             42

       

       

       

       

      File have overlap page number:

      10 Profit and loss                        20
      11 Equity change                       20

       

      thanks

       

       

       

        • 1. Re: How to write a script for report the page number in a book?
          Chinnadk Level 4

          Is this you need?

           

          var book = app.activeBook,
              _content = [];
              overlap = [];
          for(var i =book.bookContents.length-1;i>=0;i--)
          {
                  _content.push(book.bookContents[i].name + "\t" + (book.bookContents[i].documentPageRange.replace(/-[^-]+$/g,"")) + "\r");
                  if(book.bookContents[i].documentPageRange == book.bookContents[i-1].documentPageRange)
                  {
                          overlap.push(book.bookContents[i].name + "\t" +book.bookContents[i].documentPageRange + "\r" + book.bookContents[i-1].name + "\t" +book.bookContents[i-1].documentPageRange);
                      }
              }
          alert(_content.reverse());
          alert(overlap.reverse())
          

           

          Regards,

          Chinna

          • 3. Re: How to write a script for report the page number in a book?
            HarveyLiu Level 1

            Hi, Chinna

             

            I change the script into this:

             

            //---------------------------------------------------------------------------------------- ----

            var book = app.activeBook, 
                _content = []; 
                overlap = []; 
            for(var i =book.bookContents.length-1;i>=0;i--) 

                    _content.push(book.bookContents[i].name + "\t" + (book.bookContents[i].documentPageRange.replace(/-[^-]+$/g,"")) + "\r"); 
                    if(book.bookContents[i].documentPageRange == book.bookContents[i-1].documentPageRange) 
                    { 
                            overlap.push(book.bookContents[i].name + "\t" +book.bookContents[i].documentPageRange + "\r" + book.bookContents[i-1].name + "\t" +book.bookContents[i-1].documentStartPage); 
                        } 
                } 
            alert(overlap.reverse())

            //alert(_content);
                WriteToFile(_content, overlap);
            function WriteToFile(text) {
                file = new File("~/Desktop/Book contents and page number.txt");
                file.encoding = "UTF-8";
                file.open("w");
                file.write(text);
                file.close();
                file.execute();
            }
            //---------------------------------------------------------------------------------------- -----

             

             

            I got the text file:

             

            ======================================================

             

            13 Notes to account.indd 28

            ,14 Corporate Information.indd 27

            ,12 Cash flow statement.indd 26

            ,11 Equity change.indd 25

            ,10 Profit and loss.indd 20

            ,09 Income statement.indd 19

            ,08 Auditor's report.indd 18

            ,07 Directors' report.indd 17

            ,06 CG report.indd 12

            ,05 MD and A.indd 7

            ,03 Financial highlight.indd 6

            ,04 Chairman's statement.indd 3

            ,02 Summary.indd 2

            ,01 Contents.indd 1

            ======================================================

            the sequence are upside down

            ======================================================

             

             

             

            but it always report me, the book has overlop page number,

            even the book has no overlop page number

            and if the files has overlop over more 2 pages or more two files have overlop page numbers the         alert(overlap.reverse())              will not correct in report

            and the report text file has a comma at beginning of each line

            and the sequence are upside down

            why?

             

            I expected the       alert(overlap.reverse())   don't show if book has not overlap page number

            can you fix it?

             

            Harvey