13 Replies Latest reply on Feb 2, 2016 1:53 PM by Laubender

    How do I "shift-place" text?


      Hi, there.

      I have a doc in which there are three text-frames per page: frameA frameB and frameC.
      On master spread, frameA(page1) is threaded to frameA(page2), frameB(page1) is threaded to frameB(page2), and frameC(page1) is threaded to frameC(page2).
      I want to place textA in frameA, textB in frameB, and textC in frameC.

      Each text file has enough text to take up around 7 pages.

      I obviously want each story to flow neatly from frame to frame, without skipping pages, and consistently threading to the appropriate frame.

      When using the UI, I found it helpful to hold down the shift-key when placing the text (otherwise, it seems to randomly skip pages).

      How can I "shift-place" while scripting?

      Any help would be appreciated.

        • 1. Re: How do I "shift-place" text?
          Peter Kahrel Adobe Community Professional & MVP

          - check if a frame is overset

          - if it is, add a page, place a new text frame, and thread it to the overset frame.

          • 2. Re: How do I "shift-place" text?
            Schmaltzkopf Level 1

            The problem is, that when I initially place the text, the new pages are added automatically. But (as I found when using the UI) the only way (to my knowledge) to ensure the correct text-flow is to press shift when place the text. My question is, how can I accomplish that in my script?

            • 3. Re: How do I "shift-place" text?
              TᴀW Adobe Community Professional & MVP

              In this case there is no way to emulate exactly what you're doing in the UI. You have to actually write your own auto-flow function. The basic steps are as Peter outlines.



              • 4. Re: How do I "shift-place" text?
                Trevorׅ Adobe Community Professional

                This is spoon feeding you Peter's answer.

                var someText, c, doc, tf, geoBounds;
                someText = [];
                for (c = 0; c < 400;) {
                    someText[c++] = c + 1;
                someText = someText.join(")\t Some text here Some text here Some text here Some text here\n") + ")\t Some text here Some text here Some text here Some text here\n";
                doc = app.properties.activeDocument || app.documents.add();
                geoBounds = getMarginBounds(doc.pages[0]);
                tf = doc.pages[0].textFrames.add({geometricBounds: geoBounds, contents: someText});
                function autoFlow(theTextFrame, destinationPage /* [Optional Page object] defaults to following page */ ) {
                    const MAX_ADDED_PAGES = 100; // to prevent endless runs
                    const ONLY_ADD_PAGES_IF_NONE_PRESENT = true;
                    var geoBounds, doc, flow;
                    if (theTextFrame.constructor != TextFrame) return;
                    doc = theTextFrame.parent;
                    while (doc.constructor !=  Document) doc = doc.parent;
                    // This is the function that adds the pages & threaded frames as needed
                    flow = flow || function (theTextFrame, safety, destinationPage) {
                        if (!theTextFrame.overflows) return true;
                        if (!safety) return false;
                        var newFrame, currentPage, nextPage;
                        if (destinationPage && destinationPage.isValid) {
                            nextPage = destinationPage;
                        } else {
                            currentPage = theTextFrame.parentPage || theTextFrame.parent.pages[0];
                            nextPage = doc.pages[currentPage.documentOffset + 1];
                            nextPage = (ONLY_ADD_PAGES_IF_NONE_PRESENT && nextPage && nextPage.isValid) ? nextPage : doc.pages.add(LocationOptions.AFTER, currentPage);
                        // Calculate the correct geometricBounds for the textFrame
                        // Caching would be quicker but this is safer
                        geoBounds = getMarginBounds(nextPage);  /// make sure to also copy the getMarginBounds function!
                        newFrame = nextPage.textFrames.add({geometricBounds:geoBounds, previousTextFrame: theTextFrame});
                        return newFrame.contents.length ? flow(newFrame, safety--) : false;
                    return app.doScript("flow(theTextFrame, MAX_ADDED_PAGES, destinationPage);", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Auto Flow Texts");
                function getMarginBounds(thePage) {
                    var pageBounds, pageMargins, top, left, bottom, right, swap;
                    pageBounds = thePage.bounds;
                    swap = thePage.side == PageSideOptions.LEFT_HAND;
                    pageMargins = thePage.marginPreferences;
                    top = pageMargins.top;
                    left = (swap) ? pageMargins.right : pageMargins.left;
                    bottom = pageMargins.bottom;
                    right = (swap) ? pageMargins.left : pageMargins.right;
                    return [pageBounds[0] + top,
                                pageBounds[1] + left,
                                pageBounds[2] - bottom,
                                pageBounds[3] - right];
                • 5. Re: How do I "shift-place" text?
                  [Jongware] Most Valuable Participant

                  Oh I like your 'safety' catch!


                  Such a check is absolutely necessary because without it, InDesign would keep on going creating pages if it deems some of the new text could not 'fit' in the current text frame. I find this happening all the time when importing Word documents; for example, because the original author did not know how to use "align right" and so used a large Left Indent to move text to the right hand side, larger than your current text frame, or because an image or text frame is higher than your current text frame, or because InDesign cannot break a page inside a single table row where MS Word can.

                  • 6. Re: How do I "shift-place" text?
                    Trevorׅ Adobe Community Professional

                    Thanks for the compliment.

                    The functions were based on ones that I took from my batch Word importer script that some day hopefully will go on sale.

                    I also put in a check to see if content was added to the new frame which I think should catch those cases without adding the 100 blank pages 1st but the extra safety measure is likely to save a crash or 2.

                    Those Word cases are quite hard to deal with on the InDesign side.

                    • 7. Re: How do I "shift-place" text?
                      Laubender Adobe Community Professional & MVP

                      Hi Trevor,
                      thank you for sharing this and yes, I'm also all in for a "safety" catch here.


                      Let me add a note to autoFlow() :


                      I think, one can speed up construction of new text frames here, if you'd use nextTextFrame after you added a text frame to the page without using previousTextFrame in the add() method ( nextTextFrame will be used then on the text frame we previously added or the one that we started from ). It's a couple of years ago I tested this. Did not do it with your function, so this is just a suggested variant one could think about.


                      All in all, let's see what the OP is saying and if he can make use of it.
                      If I'm looking at his situation with the three stories on the master spread, he has to do a rewrite. But I hope he is getting the idea using previousTextFrame or nextTextFrame to get the stories threaded.


                      In a strict sense, to mimic "Shift"+"Place" will require even further things to add to a script, if one would like to get the flexibility of working with text frames from the master spreads. E.g. if he wants to resize the text frame on the master and the all the text frames of the story on the pages should follow along automatically.



                      • 8. Re: How do I "shift-place" text?
                        Trevorׅ Adobe Community Professional

                        Hi Uwe,


                        You should know me by now that I tend not to read the OP questions too carefully. Mainly in the forum for the crossword value


                        There's quite a bit of optimization that could be done with the script, in particular nested doScripts.  When I work on my batch Word importer I'll work on it.

                        If one changes the some text loop to < 4000 instead of < 400 one can see the slow down.  About 75 pages need to be added, that means that InDesign has to recompose the document 75 times.

                        Also having the pages panel closed should make a big difference as to shutting up the preflight profile for the script run.

                        In the meantime I'll just add the change you recommend for the OP's and others benefit and leave the other optimizations for the pro version






                        Change the line

                        newFrame = nextPage.textFrames.add({geometricBounds:geoBounds, previousTextFrame: theTextFrame});

                        to the lines

                        newFrame = nextPage.textFrames.add({geometricBounds:geoBounds});
                        theTextFrame.nextTextFrame = newFrame;
                        • 9. Re: How do I "shift-place" text?
                          Schmaltzkopf Level 1

                          Thank you very much Trevor.

                          I feel honored to have inspired such a give-and-take among the "pros".

                          Thank you for sharing something that you obviously put a lot of work (and thought) into..

                          I already have the required text frames set up in master-pages, so I am guessing that all I have to do is to check if frame is over-set (frame.overflows==true), add a page, override text-frame on next page, then thread the two frames.

                          I am trying that, and finding that on the second page, when I override the frame, it jumps - meaning it moves down about have an inch. (I did not have that problem when I over-ride the frame on the first page) How do I avoid that?



                          • 10. Re: How do I "shift-place" text?
                            Trevorׅ Adobe Community Professional

                            Hi SK


                            Send a link (dropbox etc.) to a document that you have setup and post it with the code you are using.





                            • 11. Re: How do I "shift-place" text?
                              Laubender Adobe Community Professional & MVP

                              Hi SK,

                              was the page size of the document changed before using documentPreferences or the document page setup GUI?
                              The shifting of the added text frame maybe is pointing to a bug, a strange anomaly we discussed here:


                              Override elements by script problems

                              tomas8 Apr 21, 2014

                              This question has been Answered.




                              A quick solution is outlined in answer #14 in this thread.
                              But the real problem is described and fixed in #18 and following by Marc Autret.


                              Also look at





                              • 12. Re: How do I "shift-place" text?
                                Schmaltzkopf Level 1

                                Thank you Laubender.

                                I did not change page-size. I guess it's the bug that you are referring to.

                                I will incorporate the move method.


                                Thank you again

                                • 13. Re: How do I "shift-place" text?
                                  Laubender Adobe Community Professional & MVP

                                  Hi SK,

                                  maybe you did not change the page size, but the one who created the document.
                                  (Just an assumption)