3 Replies Latest reply on Jan 8, 2015 1:30 PM by JShee

    Add cover sheet without affecting existing page numbering?

    JShee

      I guess the lack of response means either that my question is inappropriate in some way or else it's difficult or impossible to answer! Thanks for letting me post it anyway!

       

      This seems to be a very informative site (just figured out how to access it and read the responses to all the questions), and I know I'll learn a lot from reading it in the future---so thanks on that account also.   ---JCI

       

      ORIGINAL QUESTION:

      Hi,

      I have a script that inserts a new page (a cover sheet) at the beginning of a document (a chapter from a book) and makes a few other tweaks. It works perfectly _except_ for the following glitches:

      (1) The pages shuffle (I would like the cover sheet to be a recto page and the first page of the document to be a recto page as well; the rest are facing pages ).

      (2) The pages renumber (I would like to the cover sheet to be an invisible page number roman numeral "i" and the first page of the document to be page 1.1.

      (3) If I just renumber the pages manually, I also have to retype all the section names that have been inserted previously into the section marker field (I have about 160 documents to work on, so....)

       

      Is there any way to have the script avoid these problems? Please note that I inherited this script and know virtually nothing about scripting. Any help you can give—including any thoughts on whether coming up with such a script would even be possible—will be greatly appreciated!! Here is the script (and thanks in advance!):

       

      var myFolder = Folder.selectDialog ("Choose a Folder");
      var myFile;

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

      if(myFolder != null){
          myFile = myFolder.getFiles();
          for(i=0; i<myFile.length; i++) {
              app.open(File(myFile[i]));
             
      // insert page at beginning and apply master page
              app.activeDocument.pages.add(LocationOptions.AT_BEGINNING);
              var myMasterSpread = app.activeDocument.masterSpreads.item("C-WebP1");
              app.activeDocument.pages[0].appliedMaster = myMasterSpread;

      // find and remove "[advanced release]" from document
                app.findChangeTextOptions.includeMasterPages = true;
                app.findChangeTextOptions.caseSensitive = false;
                app.findTextPreferences.findWhat = "[advance release]" ;
                app.changeTextPreferences.changeTo = " ";
                app.activeDocument.changeText();
                app.findTextPreferences = null;
                app.changeTextPreferences = null;
       
      // determine if last page is blank and if so, delete
               var Lpage = app.activeDocument.pages.lastItem();
               if(Lpage.pageItems.length==0&&Lpage.guides.length==0){
                      Lpage.remove();
              }

      // save and close file
              app.activeDocument.save(new File(myFile[i]));
              app.activeDocument.close();
             
          }
      }

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

       

      Message was edited by: J Shee

        • 1. Re: Add cover sheet without affecting existing page numbering?
          Chinnadk Level 4

          Try this,

           

          var myFolder = Folder.selectDialog ("Choose a Folder");
          var myFile;
          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
          if(myFolder != null){
              myFile = myFolder.getFiles();
              for(i=0; i<myFile.length; i++) {
                  app.open(File(myFile[i]));
                 
          // insert page at beginning and apply master page
                      var _page = app.activeDocument.pages.add(LocationOptions.AT_BEGINNING);
                      var myMasterSpread = app.activeDocument.masterSpreads.item("C-WebP1");
                      app.activeDocument.pages[0].appliedMaster = myMasterSpread;
                      var section = doc.sections.add(_page);
                      section.pageNumberStyle = PageNumberStyle.LOWER_ROMAN;
                      var section1 = doc.sections.add(doc.pages.item(1));
                      section1.continueNumbering = false;
                      section1.pageStart = doc.pages.item(1);
                      section1.pageNumberStart = 1;
                      section1.sectionPrefix = "1."
                      section1.pageNumberStyle = PageNumberStyle.ARABIC
          // find and remove "[advanced release]" from document
                    app.findChangeTextOptions.includeMasterPages = true;
                    app.findChangeTextOptions.caseSensitive = false;
                    app.findTextPreferences.findWhat = "[advance release]" ;
                    app.changeTextPreferences.changeTo = " ";
                    app.activeDocument.changeText();
                    app.findTextPreferences = null;
                    app.changeTextPreferences = null;
          
          // determine if last page is blank and if so, delete
                  var Lpage = app.activeDocument.pages.lastItem();
                  if(Lpage.pageItems.length==0&&Lpage.guides.length==0){
                          Lpage.remove();
                  }
          // save and close file
                  app.activeDocument.save(new File(myFile[i]));
                  app.activeDocument.close();
                 
              }
          }
          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
          

           

          Regards,

          Chinna

          • 2. Re: Add cover sheet without affecting existing page numbering?
            JShee Level 1

            Thanks very much for your reply. The script seems to stop and line 13 and

            gives the following error:

             

            • 3. Re: Add cover sheet without affecting existing page numbering?
              JShee Level 1

              Actually, I changed the word "doc" to "document" and now the script you

              (Chinna) provided adds the page correctly and fixes the page shuffling!

              Yay!!

               

              Unfortunately, the section prefix (which varies by document/chapter,

              depending on the chapter number) and section marker (which is the chapter

              name, so also varies by document) is not preserved, but it's half-way

              there, so a huge help! Thank you very, very much!