Skip navigation
Currently Being Moderated

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

Jun 10, 2011 1:42 PM

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

 
Replies
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Jun 12, 2011 12:44 AM   in reply to Neil Weinberg

    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.

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Jun 14, 2011 9:22 PM   in reply to Neil Weinberg

    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.

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Jan 31, 2012 11:12 PM   in reply to Neil Weinberg
    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"));
    }

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Jan 31, 2012 11:21 PM   in reply to John Hawkinson

    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"));
    }

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Feb 1, 2012 12:00 AM   in reply to Neil Weinberg

    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...

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Feb 2, 2012 4:30 AM   in reply to Neil Weinberg

    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?

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Feb 2, 2012 4:01 PM   in reply to Neil Weinberg

    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.


     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Feb 2, 2012 6:02 PM   in reply to Neil Weinberg

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points