6 Replies Latest reply on Aug 15, 2013 12:50 AM by Vamitul

    Remove Empty Pages Performance

    frameexpert Level 4

      I have an 82 page InDesign CS6 document that was created from a database publishing program. Every other page is blank, so I have a script to delete the empty pages:

       

      #target indesign
      
      app.doScript(main, undefined, undefined, UndoModes.entireScript,"Remove Blank Pages");
      
      function main () {
      
          if (app.documents.length === 0) {
              alert ("Please open a document.");
              return;
          }
      
          app.scriptPreferences.enableRedraw = false;
      
          // Remove the blank pages in the document.
          removeBlankPages (app.activeDocument);
          
          app.scriptPreferences.enableRedraw = true;
      
      }
      
      function removeBlankPages (doc) {
          
          var pages = doc.pages;
          var count = pages.length - 1, i = 0;
      
          for (i = count; i >= 0; i -=1) {
              if (pages[i].allPageItems.length === 0) {
                  pages[i].remove ();
              }
          }
      }
      

       

      I am running Windows 7 with 12 GB of RAM and a i7 processor and it takes the script just under 2 minutes to delete around 40 pages. I am a little surprised at how long this script takes to run. Does anyone have any suggestions for making it faster? It is not critical--obviously it is faster than doing it by hand--but I thought it should work a little faster. Thanks in advance.

       

      Rick

        • 1. Re: Remove Empty Pages Performance
          Trevorׅ Adobe Community Professional

          Hi Rick,

           

          Please come back with feedback on the speed of runing the script below 1) in FAST_ENTIRE_SCRIPT and 2 in ENTIRE_SCRIPT undo modes.

           

          Regards

           

          Trevor

           

          #target indesign
          
          app.doScript("main()", ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT,"Remove Blank Pages"); // a lot quicker in this case should be safe
          
          function main () {
          
              if (app.documents.length === 0) {
                  alert ("Please open a document.");
                  return;
              }
          
              app.scriptPreferences.enableRedraw = false;
          
              // Remove the blank pages in the document.
              removeBlankPages (app.activeDocument);
              app.scriptPreferences.enableRedraw = true;
          
              function removeBlankPages (doc) {
          
                  var pages = doc.pages.everyItem().getElements().slice(0); // a bit quicker here
                  var i = pages.length;
                  while (i-- >1) { // a bit quicker here
                      !pages[i].allPageItems.length && pages[i].remove ();  // a bit quicker here
                      }
                  !pages[i].allPageItems.length && pages[i] != doc.pages[-1] && pages[i].remove ()
              }
          }
          
          • 2. Re: Remove Empty Pages Performance
            Trevorׅ Adobe Community Professional

            Rick

             

            Did it help?

            • 3. Re: Remove Empty Pages Performance
              frameexpert Level 4

              Hi Trevor, I am sorry for the delay in replying. No the speed is about the same. Thanks anyway.

              • 4. Re: Remove Empty Pages Performance
                UQg Level 4

                What about creating a new doc from scratch and copying only the necessary pages ?

                Adding to the end of something is often faster than removing here and there.

                • 5. Re: Remove Empty Pages Performance
                  Trevorׅ Adobe Community Professional

                  On my system which is quite an old and slow one both script run in a few seconds (mine quicker for me ) so I don't know if building a new doc will help.

                  If you have a sample document which is not confidential and can post a link for it here or send it to my email :-

                  trevor {at} creative-scripts {dot} com

                  I would be very interested to see the results on it.

                   

                  Trevor

                  • 6. Re: Remove Empty Pages Performance
                    Vamitul Level 4

                    Hello Rick!

                     

                    The problem seems to be with the document, not the script. On a test document i made, on my much inferior system, it only takes about 10-15 seconds.

                     

                    Things you could try:

                    1)  before running the script do a File->Save As.. so you collapse the undo stack (one of the biggest performance hogs for indesign).

                    2) If you have text variables, nested or grep styles, it's almost certain they are causing the slowdown. With Grep Styles, the performance hit increases more than exponentialy with the number of them (in the test i did with your script, adding 5 grep styles, on about 20 paragraphs scattered in the document increased the runtime of the script to almost 1 minute).

                    3) In some cases large tables create a noticeable performance drop, and also anchored objects, above a certain limit i did not found yet.