4 Replies Latest reply on Mar 20, 2013 3:05 PM by Dan-BTP

    Copy text frames between documents

    Dan-BTP Level 1

      I have two documents that have the same number of pages. I want to write a script to copy the text frames on each page in the source document to the corresponding page in the target document. Usually there's only one text frame on each page, and I want it positioned exactly the same in the target as in the source. I tried the following:


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

                              for (var j = 0; j < fromDoc.pages[i].textFrames.length; j++) {

                                  var fromTextFrame = fromDoc.pages[i].textFrames[j];





                                  var toPage = toDoc.pages[i];







      It gives me an error on the app.copy statement: "Cannot copy/cut due to invalid selection state."


      Can someone help me with the correct code? Than ks!

        • 2. Re: Copy text frames between documents
          Dan-BTP Level 1

          I don't see any reply.

          • 3. Re: Copy text frames between documents
            TᴀW Adobe Community Professional & MVP

            Sorry -- it's a bug in the forum software that sometimes answers

            submitted by email don't appear. What I said is:


            You should avoid using copy(), paste() etc. -- there's almost always a

            better way of doing things.


            In this case, check out the duplicate method of a textFrame:


            TextFrame.duplicate (to:varies, by:Array of Measurement Unit (Number or

            String)): PageItem

            Adobe InDesign CS6 (8.0) Object Model

            Duplicates the TextFrame at the specified location or offset.

            to: Data Type: varies

            The location of the new TextFrame, specified in coordinates in the

            format . Can accept: Array of 2 Units, Spread, Page or Layer.


            by: Data Type: Array of Measurement Unit (Number or String)

            Amount by which to offset the new TextFrame from the original

            TextFrame's position. (Optional)


            You can see that the "to" parameter of duplicate() accepts various

            things, one of which seems to be what you're looking for: page.


            So if you set myPage to be a page in a second document, presumably you

            will find that it has been duplicated to that page:




            Try that and see where the text frame lands up.


            If it's not in the right place, I would suggest copying the

            geometricBounds of the source textFrame to the new textFrame (there may

            be other ways of doing that). Just make sure that the ruler origin and

            measurement units in both documents are the same.




            • 4. Re: Copy text frames between documents
              Dan-BTP Level 1

              That was exactly what I needed. Thanks very much!