6 Replies Latest reply on Dec 27, 2008 10:35 AM by (Balázs_Slemmer)

    [CS3 JS]  Move pages from one document to another?

    Level 1
      First, a brief explanation of what I am trying to do. I have several individual chapters that I am including in an INDD book. However, I also want to be able to allow those individual chapters to stand alone, meaning that I want to add a cover/title page to each chapter file (these two pages would be placed before the current page 1 of each chapter).

      My preference would be to write a script that would open the cover/tp file and open the first chapter file; this part is no problem. Where I am running into trouble however, is the second step: moving the cover/tp pages (2 pages) over into the chapter file.

      Manually, I would open Cover.indd, activate the "move pages" menu, "Move pages: 1-2", "Destination: Before_Page 1", "Move to: Chapter1.indd".

      With over 100 chapters in the book, however, I would prefer to automate the process. I have looked into the Page.move and PageItem.move elements, but both look like they would require a location in the current document (either in (x,y) form or using "AT_BEGINNING".

      If I cannot get this to work, I will likely try to insert two blank pages, then cut/paste with a script, but I would prefer the "move" functionality, if it is possible.

      A couple of answers to potential questions:
      I can't simply place the INDD cover file b/c it uses a text variable to pull the chapter name; this personalizes each stand-alone chapter.
      Same answer to why I can't just slap the 2-page .pdf on the front of each. I need the text variable to still be active.

      Has anyone tried to move pages from one document to another using scripting? I tried to explain what I am trying to do, but if it doesn't make sense, I can try again. :)

        • 1. Re: [CS3 JS]  Move pages from one document to another?
          Loic.Aigon Adobe Community Professional
          Why not removing the text variable from the cover itself and place it at the end with the script ? Hence, you can place the cover files (as pdf or indd) rather than copy/pasting. In any case, you will have to add pages on top of your chapter.
          • 2. Re: [CS3 JS]  Move pages from one document to another?
            Level 1
            I'm afraid that placing the text variable on the page, in the correct position, might be beyond my scripting knowledge. I think that using scripting to move pages from one document to another would be a useful avenue to explore; if that does not pan out, I will probably insert two blank pages, then copy/paste.

            I like scripting the text variable option, too. Perhaps I will play with that for a while and see what I can discover.

            Thanks for replying Loic.
            • 3. Re: [CS3 JS]  Move pages from one document to another?
              Loic.Aigon Adobe Community Professional
              copy/paste is easy but...You may have page items on a locked layer, master spreads applied, items overriden,etc. At the end a lot things to deal with.
              I can't imagine placing a text variable is that complex. I will have a look and tell you.
              • 4. Re: [CS3 JS]  Move pages from one document to another?
                Loic.Aigon Adobe Community Professional
                ok here we are
                I get a raw skeleton that you will have to adjust but it's functional.
                Use a PDF for placement as you can specify the page that you want to place.
                I don't know if you can do the same for indesign files.

                So basically, it starts adding 2 pages and placeing the pdf in the same time.
                After that, it creates the textVariable and the frame that will receive it.

                Here you are:

                //If a document is open
                var ad = app.activeDocument;

                //Pages placement

                for(i=0; i<2; i++)
                //Add 2 pages on top of the document;
                var tmpPg = ad.pages.add(LocationOptions.BEFORE, ad.pages[0]);
                //Here you place your pdf
                app.pdfPlacePreferences.pageNumber = i;
                tmpPg.place(File(cover.pdf), false)
                //You should specify page x and page y but ain't found yet the way to go.

                //Text variable creation
                //Check if the textVariable named "txtVar" does not already exist...
                //if not found, create the text variable named "txtVar"
                var txtVar = ad.textVariables.add();
                txtVar.variableType =VariableTypes.CUSTOM_TEXT_TYPE;
                txtVar.name = "txtVar";
                //Set the contents of the text variables to the string "test"
                ad.textVariables.item("txtVar").variableOptions.contents = "test";

                //these coordinates don't care aboutyour units but you may adjust them to your needs
                var y1 = ad.marginPreferences.left;
                var x1 = ad.marginPreferences.top;
                var y2 = y1+5;
                var x2 = x1+25;
                var myFrame = ad.pages[0].textFrames.add({geometricBounds:[y1,x1,y2,x2]});

                //Set the contents of the frame to the text variables "txtVar"

                //You may want to stylize the txtVar
                //In this case, either you use a existing characterStyle or you create one in the script

                Bye Loic
                • 5. Re: [CS3 JS]  Move pages from one document to another?
                  Level 1
                  Thanks so much for taking the time to work this through, Loic! I really appreciate it. I will give the script a test drive tomorrow.

                  • 6. Re: [CS3 JS]  Move pages from one document to another?
                    Level 1
                    I know it's quite an old topic, but I'd like share, that you actually can move pages using scripting, and of course using the Page.move() function.

                    its syntax goes like this:
                    Page.move(to, reference, binding)

                    where 'to' stands for a LocationOption, to specify where you want to place the page relative to the reference object.
                    'reference' is the key part, because it can also be a page in any open document, you just need to refer to it.
                    'binding' defines the location of the binding spine.

                    And an example, to see this in action:
                    // Script from here
                    var coverDoc = app.documents.item('cover_document');
                    var pagesToMove = coverDoc.pages.itemByRange(0, 1);
                    var chapterDoc = app.documents.item('chapter_document');
                    pagesToMove.move(LocationOptions.BEFORE, chapterDoc.pages.item(0));
                    // Script until here

                    You may also use duplicate() the same way, if you want to keep the original pages. (however, it doesn't have the 'binding' parameter)

                    I hope it can help you!