Skip to main content
Participating Frequently
September 5, 2013
Question

How to combine multiple files in CS6

  • September 5, 2013
  • 5 replies
  • 34788 views

I am trying to combine multiple files-- book chapters-- into a single editable document in CS6. Tutorials apprea outdated

This topic has been closed for replies.

5 replies

Inspiring
September 22, 2015

Here is a full script that combines files from a book or a folder or all opened files. It has a simple interface so you can start running it independently of what you have opened.

/*Written and updated by Michael Z.

    Allows merging of files from active book or all opened documents or any chosen folder with all its subfolders.

    Allows to change the sequence of files before producing the final file.

    Allows to remove unneeded files before producing the final file.

    Allows to maintain page numbers from original documents.

    Allows to maintain original sections.

*/

#targetengine session

var list = {}, folder = "", lst = [], sn, pn, run = false;

var comp = new Window ("dialog {margins:5, spacing:5, text:'Merger'}");

var grComp = comp.add ("group {margins:5, orientation:'column'}");

var fileLst = grComp.add ("listbox", [0,0,210,250]);

fileLst.helpTip = "Press up or down keys to move items in the list.\nPress Delete to remove an item.";

fileLst.addEventListener ("keydown", function (k) {

    if (k.keyName == "Up") {

        var n = fileLst.selection.index;

        if (n > 0) {

            swap (fileLst.items [n-1], fileLst.items );

        }

    }

    if (k.keyName == "Down") {

        var n = fileLst.selection.index;

        if (n < fileLst.items.length-1) {

            swap (fileLst.items , fileLst.items [n+1]);

        }

    }

    if (k.keyName == "Delete") {

        var sel = fileLst.selection.index;

        fileLst.remove (fileLst.items[sel]);

        if (sel > fileLst.items.length-1)

            fileLst.selection = fileLst.items.length-1;

        else

            fileLst.selection = sel;

    }

});

var rbComp = comp.add ("panel {margins:5, spacing:0, orientation:'column', size:[210,90]}");

var aodocs = rbComp.add ("radiobutton {text:'All opened documents'}", [0,0,195,20]);

aodocs.onClick = function () {

    fileLst.removeAll ();

    if (app.documents.length>0) {

        for (i = 0; i < app.documents.length; i ++) {

            fileLst.add ("item", app.documents.name);

            list [app.documents.name] = app.documents.fullName;

        }

    } else {

        alert ("No documents opened.");

        aodocs.value = false;

        return;

    }

}

var abdocs = rbComp.add ("radiobutton {text:'Active book documents'}", [0,0,195,20]);

abdocs.onClick = function () {

    fileLst.removeAll ();

    if (app.books.length>0) {

        for (i = 0; i < app.activeBook.bookContents.length; i ++) {

            fileLst.add ("item", app.activeBook.bookContents.name);

            list [app.activeBook.bookContents.name] = app.activeBook.bookContents.fullName;

        }

    } else {

        alert ("No books opened.");

        abdocs.value = false;

        return;

    }

}

var flddocs = rbComp.add ("radiobutton {text:'All documents in a folder'}", [0,0,195,20]);

flddocs.onClick = function () {

    fileLst.removeAll ();

    var bf = Folder.selectDialog ("Select folder with files.");

    if (bf) {

        var myFileList = bf.getFiles ("*.indd");

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

            var myFile = myFileList ;

            list [myFile.displayName] = myFile.fsName;

            fileLst.add ("item", myFile.displayName);

            folder = bf.fsName;

        }

    }else {

        alert ("No folder selected.");

        flddocs.value = false;

        return;

    }

}

var fldAlldocs = rbComp.add ("checkbox {text:'Including subfolders'}", [15,0,180,20]);

fldAlldocs.onClick = function () {

    if (Folder (folder).exists && fldAlldocs.value == true) {

        fileLst.removeAll ();

        var myFileList = getSubFolders (Folder (folder));

        for (m in myFileList) {

            fileLst.add ("item", m);

        }

    }else {

        alert ("No folder selected.");

        fldAlldocs.value = false;

        return;

    }

}

var secComp = comp.add ("panel {margins:5, spacing:0, orientation:'column', size:[210,50]}");

var sec = secComp.add ("checkbox {text:'Keep sections'}", [0,0,195,20]);

var pgNum = secComp.add ("checkbox {text:'Keep page numbers'}", [0,0,195,20]);

sec.onClick = function () {

    if (sec.value == false)

        pgNum.value = false;

}

pgNum.onClick = function () {

    if (sec.value == false)

        sec.value = true;

}

var btnComp = comp.add ("panel {margins:5, orientation:'row', size:[210,35]}");

var okBtn = btnComp.add ("button {text:'OK', size:[90,20]}");

var cancBtn = btnComp.add ("button {text:'Cancel', size:[90,20]}");

function swap (x, y) {

    var temp = x.text;

    x.text = y.text;

    y.text = temp;

}

okBtn.onClick = function () {

    for (i = 0; i < fileLst.items.length; i ++)

        lst.push (fileLst.items.text);

    sn = sec.value;

    pn = pgNum.value;

    run = true;

    comp.close ();

}

cancBtn.onClick = function () {

    comp.close ();

}

comp.show ();

if (run) {

    app.doScript (function () {

        app.scriptPreferences.userInteractionLevel=UserInteractionLevels.NEVER_INTERACT;

        var doc0 = app.open (File (list[lst[lst.length-1]]), true, OpenOptions.OPEN_COPY);

        var face = doc0.documentPreferences.facingPages;

        doc0.documentPreferences.facingPages = false;

        for (a = lst.length - 2; a > -1; a --) {

            var tmpdoc = app.open (File (list[lst]), false, OpenOptions.OPEN_COPY);

            tmpdoc.documentPreferences.facingPages = false;

            tmpdoc.pages.everyItem ().duplicate (LocationOptions.BEFORE, doc0.pages[0]);

            if (sn)

                doc0.pages[0].appliedSection.continueNumbering = false;

            if (pn) {

                doc0.sections.add (doc0.pages[0], {pageNumberStart:tmpdoc.pages[0].appliedSection.pageNumberStart});

                doc0.pages[0].appliedSection.pageNumberStyle = tmpdoc.pages[0].appliedSection.pageNumberStyle;

            }

            tmpdoc.close (SaveOptions.NO);

        }

        if (!sn && doc0.sections.length > 1)

            doc0.sections.itemByRange (1, doc0.sections.length-1).remove ();

        doc0.documentPreferences.facingPages = face;

        app.scriptPreferences.userInteractionLevel=UserInteractionLevels.INTERACT_WITH_ALL;

    }, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Merge Documents");

}

function getSubFolders (theFolder) {

    var myFileList = theFolder.getFiles ();

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

        var myFile = myFileList ;

        if (myFile instanceof Folder) {

            getSubFolders (myFile);

        }

        else if (myFile instanceof File && myFile.name.match (/\.indd$/i)) {

            list [myFile.displayName] = myFile.fsName;

        }

    }

    return list;

}

cjsupleeAuthor
Participating Frequently
September 23, 2015

Thank you so much. I am not sure how to implement this (I am a writer, not much of a techie) but I have a pal who can help. Thanks!

Colin Flashman
Community Expert
Community Expert
July 11, 2014

following on from Sandee Cohen's post no.18, the location of the script has moved to:

http://www.simonwiscombe.com/indesign-merging-all-files/

and it is worth noting that the script initially merged files that were all 1pp long each.

Simon did make a modification to it later on in the article so that the script would merge files of all lengths, but when I ran the script, it produced an error to do with line 18. The line:

var sourceFolder = Folder.selectDialog(“Select a folder with source InDesign files.”);

needs to be replaced with

var sourceFolder = Folder.selectDialog('Select a folder with source InDesign files.');

(double quotes were swapped out for single quotes)

I have only tested the script with varying page lengths with minimal objects on the pages to determine if the files merged. So far so good. The earlier version that merged 1pp files only would fail if fonts/links were missing as any dialog box upon opening seems to interfere with the script. I feel that the newer script will do the same thing.

I know this is an older thread but given I just had the same experience, I thought the revised script would help a few people.

Colin

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!
Sandee Cohen
Legend
September 6, 2013

Carol,

I think what you wanted in your original post is not what has been suggested for you.

You wanted all the files in a single, editable, InDesign document. Why?

If you want to be able to export as a single PDF, you don't have to merge your files together.

Creating a Book file can allow you to export and print a range of documents together. But each document would still be a separate file.

But if it is vital that all the pages be in one actual file, then you can use the Move Pages command in the Pages panel to move pages from one file to another.

So, what exactly do you want to do?

cjsupleeAuthor
Participating Frequently
September 6, 2013

I need to combine the chapters of a book, now in separate ID files, into one file so it can be converted to an E-book. I wrote the chapters separately to protect against massive loss of data, by some unforeseen circumstance, and it has worked extremely well. The original printer also preferred it that way, since it was a small house and needed the flexibility to change folios, etc. But now it must be combined. I appreciate your help.

Carol J. Suplee

BobLevine
Community Expert
Community Expert
September 6, 2013

Carol, be careful when replying by email. I don't think you really want all of your personal info here.

I've edited your address and phone number out of the last post.

Willi Adelberger
Community Expert
Community Expert
September 5, 2013

Create a book (File > New > Book…)

Put these single files as chapter in the bokk and leave them as separate files. From the book panel you can output these files as single PDF or whatever you want.

cjsupleeAuthor
Participating Frequently
September 5, 2013

It is still a mystery.  I choose + in the book file box and just once I was somehow able to insert one file from my book. From then on, in the add documents box,  it wanted only to resave the next file to its home file again.  A vicious circle. Could never get a second file to import. I am on an Imac Lion OSX. Is that the hangup? It is frustrating!!!!!!!!!!  I have deleted all tries (not my files) but so far have spent too many hours trying to make it work. I also watched another tutorial that did not produce any results.

But thanks for trying to help. Not sure what I can do now. I am using CS6.

Carol

Marvest
Inspiring
September 5, 2013

Your chapters need to be Indesign documents (each one) to be able to add them to the book file.

Mike Witherell
Community Expert
Community Expert
September 5, 2013