2 Replies Latest reply on May 26, 2014 6:21 AM by markc0

    yet another ask for help with javascript

    markc0

      Hello i have created the code below as i have a layout with 5 pages , i wanted to export each page as a new doc (keeping the existing page setup)

      however what has happened is that it has created a new doc(layout) for each page

      so the output if 5 new docs with the same 5 pages on as the orignal doc.

      How can i adjust this so that each 5 new docs have just one page on thats different on each document

      i tried chnaging  curDoc.save(saveFile); to  eachpage.save(saveFile);

      but this did not work

      thanks

       

      var curDoc = app.activeDocument;

      var myPages =  curDoc.pages; 

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

                 var eachpage = myPages[i];

      var Name = curDoc.name.replace(/\.[^\.]+$/, '');

      var saveFile= File("~/Desktop/guides/Test" + Name + ".indd")

       

         //app.activeDocument.save(saveFile);

         curDoc.save(saveFile);

       

         }

        • 1. Re: yet another ask for help with javascript
          Jump_Over Level 5

          Hi,

           

          It can be a pretty complex subject if your doc has facing pages

          and some pageItems come from masterSpreads (i.e. page numbers)

           

          If not use this:

          var
            destFolder = "~/Desktop/test/",
            curDoc = app.activeDocument,
            tempFile = new File(destFolder + "temp.indd"),
            myPages =  curDoc.pages.everyItem().getElements(),
            len = myPages.length;
          
          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
          curDoc.save();
          curDoc.saveACopy(tempFile);
          
          while (len-->0) {
            curFile = new File(destFolder + ( "00" + curDoc.pages[len].name ).slice(-3) + "_" + curDoc.name );
            tarDoc = app.open(tempFile,false);
            tarDoc.pages[len].move(LocationOptions.AT_END);
            tarDoc.pages.itemByRange(0,-2).remove();
            tarDoc.saveACopy(curFile);
            tarDoc.close();
            }
          
          tempFile.remove();
          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
          

           

          Jarek

          • 2. Re: yet another ask for help with javascript
            markc0 Level 1

            Many thanks although I see quite abit different from my attempt

             

            Sent from my iPad