2 Replies Latest reply on Dec 17, 2012 5:55 AM by Marco Lugli

    Copy page items between 2 documents with same number of pages

    Marco Lugli Level 1

      Hello all,

      I have two Indesign Documents with the same number of pages; I'd like to copy every page item from source document and paste it in place on the corresponding page on destination document.

       

      This is my starting point (which stops at page 1..):

       

      //--- BEGIN CODE ---

       

      var docSource = app.documents.[0];

      var docDestination = app.documents.[1];

       

      function copyPages(){

      for (i=0; i<docSource.pages.length; i++){

       

        app.activeDocument = docSource;

       

        var myPageSource = docSource.pages.[i];

       

        var myActivePageSource = app.layoutWindows[i].activePage;

       

        var myPageSourceItems = myActivePageSource.pageItems.everyItem().select(SelectionOptions.ADD_TO);

       

        app.copy(); 

       

        app.activeDocument = docDestination;

       

        var myPageDestination = docDestination.pages.[i];

       

        var myActivePageDestination = app.layoutWindows[i].activePage;

       

        app.pasteInPlace();

       

      }

      }

      copyPages();

       

      //---- END CODE ---

       

      Any help would be much appreciated,

       

      Thanks in advance

        • 1. Re: Copy page items between 2 documents with same number of pages
          Jump_Over Level 5

          Hi,

           

          There are some syntax/typo errors inside your code.

           

          try this:

          ___________________________________________________________________

          var docSource = app.documents.item("1stName");     // input the proper name

          var docDestination = app.documents.item("2ndName")     // input the proper name

          function copyPages ( docSource, docDestination ) {

          for (i=0; i<docSource.pages.length; i++){

              app.activeDocument = docSource;

              var myPageSourceItems = app.select(app.activeDocument.pages[i].allPageItems);

              app.copy(); 

              var myPageDestination = docDestination.pages[i];

              docDestination.layoutWindows[0].activePage = myPageDestination;

              docDestination.layoutWindows[0].bringToFront();

              app.pasteInPlace();

              }

          }

          copyPages(docSource, docDestination);

          ____________________________________________________________

           

          Notice that:

          - app.documents[0] refer to a currently activated doc (so could be different while script execution)

          - var myActivePageSource = app.layoutWindows[i].activePage means... your each page should be open in a separate window;

           

          rgds

          • 2. Re: Copy page items between 2 documents with same number of pages
            Marco Lugli Level 1

            Hi Jump_Over,

            I tried your code and it worked perfect! Thank you for your support (..and also for your specifications).