17 Replies Latest reply: Feb 2, 2012 6:39 PM by Neil Weinberg RSS

    Import multiple Word docs to multiple pages with same master page?

    Neil Weinberg Community Member

      Hi, I should start by saying I have no scripting experience.  However, I am wondering if there is a simple script available for the following issue:

       

      I have set up a master page with three linked text boxes. Right now, I use Cmd+D to select a word file, and then Shift+click in the first box to place the text on the page. But I have 125 pages that are exactly the same layout, just different Word files to be imported. I could repeat this process 125 times, but I am wondering if there is a way to tell InDesign to create 125 pages using Master Page X and import one file for each?

       

      I am using InDesign CS5 v 7.0.4 on Mac OSX Snow Leopard v 10.6.7

       

      Thank in advance for any help you can offer,

      NW

        • 1. Re: Import multiple Word docs to multiple pages with same master page?
          John Hawkinson Community Member

          Well, it's not too tough. Let's assume you've created the pages with master page X via the regular UI, since that's easy enough.

          Then for each page, you must override the master page item and then place the document within it. Untested of course:

           

           

          var
              d=app.activeDocument,
              p=d.pages,
              i, frame;
          
          for (i=0; i<p.length; i++) {
              frame = p[i].appliedMaster.textFrames[0].override(p[i]);
              frame.place(new File("/path/to/page"+p[i].name+".doc"));
          }
          

           

          Which should place page1.doc in the first textframe on the master applied to page 1, page2.doc on page 2, etc.

           

          It's a shame you can't just use Data Merge for this. Oh well.

          • 2. Re: Import multiple Word docs to multiple pages with same master page?
            Neil Weinberg Community Member

            Thank you! This seems a little beyond me right now, but I will try to figure it out.  Data Merge was exactly what I was thinking of, but as you say, it didn't work.

            • 3. Re: Import multiple Word docs to multiple pages with same master page?
              John Hawkinson Community Member

              Well, you can always submit a feature request (http://adobe.com/go/wish). Anyhow, if any of the above is unclear, just ask. It's a simple script, so it's not a problem to go line-by-line if that's what it takes.

              • 4. Re: Import multiple Word docs to multiple pages with same master page?
                Neil Weinberg Community Member

                Hi John,

                 

                I'm sorry for the long delay in following up again! Firstly, thanks again for your help with this. I tried working with the script you provided, but ran into some trouble, so I ended up just importing the files manually. Well, the same project is back this year, so I looked up this post again and had another go at it... with some success! I was able to import the word documents as long as there was only one text frame on the master page. However, when I created multiple text frames (the text in the word document needs to flow from frame 1 to frame 2), it always imported into frame 2 and skipped frame 1. In case it is helpful to understand what I mean, I attach two screenshots. The first (sans text) is the master page, and the second is Page 1 after running the script. I added the labels Frame 1 and Frame 2 to Page 1, not the Master, because otherwise the text gets imported into the frame with the words "Frame 2". I suspect I have to label the frames in InDesign and then add something to the script that says insert into the Frame 1, but I'm not sure how to do that.

                 

                Many thanks,

                Neil

                Region capture 7.pngRegion capture 8.png

                • 5. Re: Import multiple Word docs to multiple pages with same master page?
                  John Hawkinson Community Member
                  I was able to import the word documents as long as there was only one text frame on the master page. However, when I created multiple text frames (the text in the word document needs to flow from frame 1 to frame 2), it always imported into frame 2 and skipped frame 1. In case it is helpful to understand what I mean, I attach two screenshots. The first (sans text) is the master page, and the second is Page 1 after running the script. I added the labels Frame 1 and Frame 2 to Page 1, not the Master, because otherwise the text gets imported into the frame with the words "Frame 2". I suspect I have to label the frames in InDesign and then add something to the script that says insert into the Frame 1, but I'm not sure how to do that.

                  It wasn't clear from your narrative in June that the text frames were linked, and that the text needed to flow between frames.

                  The script, as implemented, only overrides one text frame, (textFrames[0],  which is the top-most text frame in the stacking order), and then places the text in it. Clearly that's not correct for your scenario.

                   

                  You mention 3 frames but only mention flowing between 2 frames.

                  Anyhow, it sounds like you want the script to override all 3 text frames, and then to place in the first textframe.


                  The first is easy, the question is really what should happen when there are more than 3 text frames -- should it override all text frames, or only some. You could specify which ones with a Script Label, or you could do something more clever. For the moment, let's just override all text frames.

                  Then you have to specify which one to place into. You could just select the frame you want and Arrange > Bring To Front. Or we could specify frames[2], which should be the 3rd-from-the-top (after frames[0] and frames[1]). I'll do the latter, but feel free to keep the script the same and do the former:

                   

                  var
                      d=app.activeDocument,
                      p=d.pages,
                      i, frames;

                  for (i=0; i<p.length; i++) {
                      frames = p[i].appliedMaster.textFrames.everyItem().override(p[i]);
                      frames[2].place(new File("/path/to/page"+p[i].name+".doc"));
                  }

                  • 6. Re: Import multiple Word docs to multiple pages with same master page?
                    John Hawkinson Community Member

                    Whoops! Unfortunately that doesn't work, because overriding the textframes individually appears to break the link to them.

                    I'm not sure what the "right" fix is for that -- anyone?

                     

                    The cheap hack is to Group the objects on the master page and override the group:

                     

                     

                    var
                        d=app.activeDocument,
                        p=d.pages,
                        i, frames;

                    for (i=0; i<p.length; i++) {
                        frames = p[i].appliedMaster.groups[0].override(p[i]);
                        frames.textFrames[2].place(new File("/path/to/page"+p[i].name+".doc"));
                    }

                    • 7. Re: Import multiple Word docs to multiple pages with same master page?
                      Neil Weinberg Community Member

                      Thanks, John!

                       

                      I'm sorry about the lack of clarity in my earlier posts. I meant that there will be multiple text frames on the page, but only two of them will contain the text that needs to be imported. The other frames will have static text or a story that will flow along side these frames.

                       

                      Your suggestion to select the first frame I want the text to load into and then Arrange > Bring to Front actually did the trick, even without editing your original script. Below are two screenshots that I hope will expalin what I mean. As you will see the top frame and the bottom frame are linked, but the middle frame contains static text. The first image is the master page, the second image is page 1 after running your script.

                       

                      I will try implementing this with the real pages tomorrow, and if anything funky happens there, I'll be back to let you know!

                       

                      Again, thank you very much!

                       

                       

                      Region capture 2.pngRegion capture 1.png

                      • 8. Re: Import multiple Word docs to multiple pages with same master page?
                        Neil Weinberg Community Member

                        One more follow-up question. I have no scripting experience, but I would love to learn more. Do you have any recommendations for books, websites, videos or other materials that might be a good place to start? Or do you think I need to take a formal class at the local university?

                        • 9. Re: Import multiple Word docs to multiple pages with same master page?
                          John Hawkinson Community Member

                          Well, you should check out Where do I find the help docs? at the top of the forum page.

                           

                          I would certainly recommend starting there and with Adobe's documentation.

                          You are unlikely to find a formal class at your university on InDesign scripting. You can find classes on the Javascript language, but I fear you'll find they are almost all targetted at using it in web browsers, which have a very different environment that is not wholly applicable to InDesign...

                          • 10. Re: Import multiple Word docs to multiple pages with same master page?
                            Neil Weinberg Community Member

                            Oops! I'm sorry for not having looked through the Overview tab more thoroughly. I'll start with the Adobe materials and hopefully work my way up the ladder from there. Thank you.

                            • 11. Re: Import multiple Word docs to multiple pages with same master page?
                              Neil Weinberg Community Member

                              Hi John,

                               

                              Sorry to bother you, but I am stuck again! My final master page has multiple elements with three linked text frames that I want to import the text from the word documents into. (This is different than what I said earlier, when I thought there would only be two linked text frames for the imported text.) I tried revising the script to match what you have in post 6, but I get the following error message:

                               

                              Region capture 6.png

                               

                              The text was imported into the proper frames on page 1, but none of the other pages.

                               

                              Could this be related to the fact that my master page uses facing pages, so I have duplicate layouts on the facing pages (the margins are different however—they are bigger on the spine)?

                               

                              Thanks again for your help... and patience!!

                              • 12. Re: Import multiple Word docs to multiple pages with same master page?
                                John Hawkinson Community Member

                                That script assumes that the textframes to override are grouped on the master page, and they are the uppermost group.

                                So:

                                 

                                Are they grouped? If not, group them.

                                 

                                Are they the uppermost group? If not, Arrange > Bring to Front.

                                 

                                It might be running afoul of facing page issues...try turning off facing pages temporarily?

                                • 13. Re: Import multiple Word docs to multiple pages with same master page?
                                  Neil Weinberg Community Member

                                  Yup, it was indeed the facing pages that caused the problem. Sorry for not trying that sooner. The problem is that the margins are not the same on the facing pages, so if I turn off facing pages, import the files and then turn it back on, the text frams on one side are out of alignment. I'm not sure where to go from here. I think there might be a solution if I label the frame groups, so I have been researching that, but so far no luck. I guess another option might be to look for a script that tells the text group to align its outside edge with the outside margin?

                                  • 14. Re: Import multiple Word docs to multiple pages with same master page?
                                    John Hawkinson Community Member

                                    Sorry. The problem is that InDesign treats both pages of the master spread together, I guess you have to do some hoop-jumping. Try this, then:

                                     

                                    var
                                        d=app.activeDocument,
                                        p=d.pages,
                                        i, frames, masterPage, page;
                                     
                                    for (i=0; i<p.length; i++) {
                                        page = p[i];
                                        masterPage = page.appliedMaster.pages[(page.side===PageSideOptions.LEFT_HAND)?0:1];
                                        frames = masterPage.groups[0].override(page);
                                        frames.textFrames[2].place(new File("/path/to/page"+page.name+".doc"));
                                    }
                                    

                                    We have to check the whether the page is a left-hand page, and if it is, use the first page (0) of the master spread, otherwiseuse the right page.


                                    • 15. Re: Import multiple Word docs to multiple pages with same master page?
                                      Neil Weinberg Community Member

                                      You are the best! This worked like a charm. I am going to use this as a template to try my hand at scripting by working on variations, such as importing eps files into image frames, importing files into even pages only, etc. So I am doubly grateful—for the immediate script, which will save me substantial time, and for a base script to work from for my own education.

                                       

                                      Thank you very much!

                                      Neil Weinberg

                                      • 16. Re: Import multiple Word docs to multiple pages with same master page?
                                        John Hawkinson Community Member

                                        You are the best! This worked like a charm. I am going to use this as a template to try my hand at scripting by working on variations, such as importing eps files into image frames, importing files into even pages only, etc. So I am doubly grateful—for the immediate script, which will save me substantial time, and for a base script to work from for my own education.

                                        You're welcome. Please mark the thread as Answered.

                                         

                                        If you're going to expand this, it is probably well worth your time to investigate the Script Label (in its own panel) or Name (in the layers panel) as a tool to mark page elements interactively and then reference items with a particular label in your script.

                                         

                                        Depending on the uppermost group or whatnot is not a great strategy as things get more complex.

                                        • 17. Re: Import multiple Word docs to multiple pages with same master page?
                                          Neil Weinberg Community Member

                                          Sorry, I was responding through email, but I just marked past 14 as the correct answer.

                                           

                                          Thanks for the suggestions, too. I will definitely look into Script Labels further!