Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Script to interleave two InDesign files of equal page counts

Participant ,
Nov 01, 2008 Nov 01, 2008
I need to merge two documents so that the new one has pages alternating one from each of the source documents. The source files have the same page dimensions and page counts. Or it could be done by inserting pages from one into the other to produce the interleaved merged document.

This could also work if the source files were sections in a book and a script would print pages alternating one from each section of the book. The script could print to Adobe pdf and produce an interleaved pdf.

Although my purpose is different, this would be needed by some one scanning documents with a non duplexing scanner to merge the scanned pages into one pdf. I have searched the forums with no results.

Does anyone know of any scripts to do this, or similar ones that can be modified to do it?

Thanks,

Al
TOPICS
Scripting
9.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 01, 2008 Nov 01, 2008
Hi,
Maybe a smart way to get your goal without messing indesign files and dealing with document properties is to use your pdfs.

I mean,

1. either you wrote a javascript that you use into Acrobat for creating a new PDF file with the files that are opened or files that you may want to choose.

2. either you place the pdfs into a new indesign file (as all the page dimensions are the same) dealing with the disposition, then exporting to a new pdf. Obviously the safest way in my opinion.
Your pdf can be indesign generated pdf in the first part of the script or pdf that you call from a choos file dialog. Up to you.

3. You can of course create a mixed indesign file dealing with copy & paste but I think it's a lot of work for nothing.

Will try to write something for you.

Loic
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 01, 2008 Nov 01, 2008
Hi Loic,

Thanks for the response.

I have no scripting experience, so starting from scratch is not an option for me.

I agree that the copy/paste is out of the question. My two source files (either ID or pdf) have 200+ pages each. So, either a javascript for InDesign or for Acrobat would work. A choose files dialog would be a nice enhancement, but an Acrobat script that would work with two open files to produce the interleaved merged file would work. Let me know if you need more information.

Thanks,

Al
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 01, 2008 Nov 01, 2008
OK I think I have all I need.
I will have a look for the smartest approach, Acrobat or Indesign.
Right now, I would say Acrobat cause it doesn't take care of individual file formats and the native process may work faster. Will see.
Loic
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 01, 2008 Nov 01, 2008
If we're talking CS3 or later, another approach would be to create a third document and then place pages from the other two alternatively.

Dave
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 01, 2008 Nov 01, 2008
Hi Dave,

Yes CS3. Is there already a script to alternatively place pages from two source IDCS3 files? I am aware of Olav Kvern 's script for placing pdf pages, and Scott Zanelli's for placing pdf or ID pages, but those deal with single file sources.

Thanks,

Al
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 01, 2008 Nov 01, 2008
Al,

I doubt it. It's not really a common requirement.

What to do if the two documents are of different length? Leave the pages blank for the shorter one? Or should the script just stop in its tracks if the two documents don't match in this regard?

Dave
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 01, 2008 Nov 01, 2008
Of course Dave,
Completely forgot this one ;-)
Loic
In fact, this may be the quickest way to achieve the process although as you underline, it needs CS3. Well thought.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 01, 2008 Nov 01, 2008
It may not be really common, but not that unusual either. As mentioned in my OP, it would be useful to users scanning long paper documents to pdf with a non duplexing scanner.

In my case the counts are equal. In the scanning case they would not differ by more than one page, in the case of an odd page count, assuming that any intermediate blank pages from the long paper document are either included in the scanning or inserted as needed in Acrobat as can be done with a blank page at the end to the shorter one to make them equal.

As for what to do with files of greater unequal length, the script could optionally stop at the shorter count, or insert alternating blank pages to complete the long count. But I agree that this would involve additional programing just to accommodate truly uncommon cases.

Al
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 01, 2008 Nov 01, 2008
Al,

Here you go. I've only tested it with CS4, but I'm fairly sure it will work with CS3. It does, however, expose a bug in CS4. After the first placed page, the master items don't appear in the placed pages.

This is a very nasty bug. I trust that Adobe sits up and takes notice and issues a quick fix, although experience says we'll be lucky to see 4.01 inside of six months.
//DESCRIPTION: Merge the two open documents


(function() {
if (app.documents.length != 2) {
alert("Please open two InDesign documents and try again."); return;
} else {
var doc1 = app.documents[0];
var doc2 = app.documents[1];
if (checkPageSizes(doc1, doc2)) {
// docs have same page sizes
var pHt = doc1.documentPreferences.pageHeight;
var pWd = doc1.documentPreferences.pageWidth;
if (!doc1.saved || !doc2.saved) {
if (!confirm("Both documents will be saved before closing. Continue?")) {
return;
}
}
var doc1Lim = doc1.pages.length;
var doc2Lim = doc2.pages.length;
var file1 = doc1.fullName;
var file2 = doc2.fullName;
doc2.close(SaveOptions.yes);
doc1.close(SaveOptions.yes);
app.documentPreferences.facingPages = false;
newDoc = app.documents.add();
newDoc.documentPreferences.properties = {
pagesPerDocument:Math.max(doc1Lim, doc2Lim)*2,
pageHeight:pHt,
pageWidth:pWd
}
app.importedPageAttributes.importedPageCrop = ImportedPageCropOptions.cropContent;
var j = 0;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
while (true) {
app.importedPageAttributes.pageNumber = j + 1;
if (doc1Lim > j) {
newDoc.pages[j * 2].place(file1);
}
app.importedPageAttributes.pageNumber = j + 1;
if (doc2Lim > j) {
newDoc.pages[(j * 2) + 1].place(file2);
}
j++;
if (j > Math.max(doc1Lim,doc2Lim)) break;
}
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
} else {
alert("Two documents must have the same page size"); return;
}
}
function checkPageSizes(doc1, doc2) {
var d1ht = doc1.documentPreferences.pageHeight;
var d1wd = doc1.documentPreferences.pageWidth;
var d2ht = doc2.documentPreferences.pageHeight;
var d2wd = doc2.documentPreferences.pageWidth;
if (d1ht != d2ht) return false;
if (d1wd != d2wd) return false;
return true;
}
}())
Dave
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 19, 2014 Mar 19, 2014

tried this in CS5, on a mac.

froze the program, fyi.

edit: although it did freeze up, it was working in and generated about 1/3 of what i needed, i guess i'll have to let it run a while longer for the size of the file i'll be generating.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 27, 2016 Jan 27, 2016

I get this error:

Interleave Doc error.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 28, 2016 Jan 28, 2016

Some coying played a trick on you. Replace this line:

if (doc1Lim > j) {

with this:

if (doc1Lim > j) {

Peter

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 02, 2016 Feb 02, 2016

Thanks, pkahrel. I didn't think of comparing the pasted text to the above original. I.ve written applescript, not so much Java.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 02, 2016 Feb 02, 2016

pkahrel,

I fixed the code as suggested above. I checked every line against the original.

I open two 20 pg Indesign docs, run the script and now get this error.

It closes the Doc A and Doc B, creates a new Untitled doc that is correctly 40 pages.

I wish could step through the script and see the results of each variable change to track down the problem.

BTW, the Doc A.indd does exist on the desktop as well as Doc B. innd.

I thought maybe it was having trouble since both docs are using Master page A, so in doc B, I changed its master to "B".

I also told each 20 pages to Override Master page items.

Still no luck. Any help is appreciated. Using in Indesign CC 2015.

Java error2.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2016 Feb 02, 2016

Sorry, I don't know that script at all, I just spotted that error.

I can't tell what's causing the problem at line 37.

> I wish could step through the script and see the results of each variable change to track down the problem.

You can:

1. Open the script in the ESTK (right-click it in the Script panel, then choose Edit Script).

2. Go to the Debug menu and select Step Over. This starts running the script and pauses at every line. In the console you can type a value to inspect it, and the Data browser shows details of the contents of various variables.

3. To go to the next line, select Step Over again.

The ESTK has its quirks (to put it mildly) but it's the only debugging tool for JavaScripts, and it's workable enough. You can read up on it in the JavaScripts Tools Guide (see the ESTK's Help menu), chapter 2.

Peter

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 02, 2016 Feb 02, 2016

Tried that. Stepping through, the ESTK does not work within Indesign. Even though you might have the 2 docs opened, while stepping, it doesn't know Indesign has the docs opened. It errors saying, "open two documents". Real frustrating.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 02, 2016 Aug 02, 2016

Bit of an old thread, I got the script to work that Dave_Saunders posted above, it's great. I just wanted to know if it's possible to include the bleed from the original two documents through to the final interwoven document? I have a work around that involves changing the document sizes to include the bleed, but it would be great if the script could do this.

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 03, 2016 Aug 03, 2016

There is a line in the code above from Dave Saunders:

app.importedPageAttributes.importedPageCrop = ImportedPageCropOptions.cropContent;

Can it be changed to include the bleed instead of crop only?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 03, 2016 Aug 03, 2016

Replace cropContent with cropBleed.

Peter

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 03, 2016 Aug 03, 2016

Thanks pkahrel.

I tested it. The art comes in with bleed but places at 0,0 instead of -.125", -.125" coordinates offsetting the page content. Not sure where to make the script offset. It doesn't have to be variable, we always use .125" bleed.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 04, 2016 Aug 04, 2016

Yeah it would be great if the placed page content was placed at the bleed bounds rather than page bounds.

I've tweaked the script so that it takes the bleed from 'Doc1' and checks that 'Doc2' has the same size bleed. I've also tweaked it so that the bleed amount is added into the newly created document. However i'm just not sure how to specify the position of the place page content.

My tweaked script is here.

(function() {

  if (app.documents.length != 2) {

    alert("Please open two InDesign documents and try again."); return;

  } else {

    var doc1 = app.documents[0];

    var doc2 = app.documents[1];

    if (checkPageSizes(doc1, doc2)) {

// docs have same page sizes

      var pHt = doc1.documentPreferences.pageHeight;

      var pWd = doc1.documentPreferences.pageWidth;

      var myDocBleed = doc1.documentPreferences.documentBleedTopOffset;

      if (!doc1.saved || !doc2.saved) {

        if (!confirm("Both documents will be saved before closing. Continue?")) {

          return;

        }

      }

      var doc1Lim = doc1.pages.length;

      var doc2Lim = doc2.pages.length;

      var file1 = doc1.fullName;

      var file2 = doc2.fullName;

      doc2.close(SaveOptions.yes);

      doc1.close(SaveOptions.yes);

     

   

      app.documentPreferences.facingPages = false;

      newDoc = app.documents.add();

      newDoc.documentPreferences.documentBleedTopOffset = myDocBleed;

      newDoc.documentPreferences.documentBleedUniformSize = true;

      newDoc.documentPreferences.properties = {

        pagesPerDocument:Math.max(doc1Lim, doc2Lim)*2,

        pageHeight:pHt,

        pageWidth:pWd

      }

      app.importedPageAttributes.importedPageCrop = ImportedPageCropOptions.cropBleed;

      var j = 0;

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;

      while (true) {

        app.importedPageAttributes.pageNumber = j + 1;

        if (doc1Lim > j) {

          newDoc.pages[j * 2].place(file1);

        }

        app.importedPageAttributes.pageNumber = j + 1;

        if (doc2Lim > j) {

          newDoc.pages[(j * 2) + 1].place(file2);

        }

        j++;

        if (j > Math.max(doc1Lim,doc2Lim)) break;

      }

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

    } else {

      alert("The two documents must have the same page size and bleed amount. Change these and re-run the script."); return;

    }

  }

  function checkPageSizes(doc1, doc2) {

    var d1ht = doc1.documentPreferences.pageHeight;

    var d1wd = doc1.documentPreferences.pageWidth;

    var d1bleed = doc1.documentPreferences.documentBleedTopOffset;

    var d2ht = doc2.documentPreferences.pageHeight;

    var d2wd = doc2.documentPreferences.pageWidth;

    var d2bleed = doc2.documentPreferences.documentBleedTopOffset;

    if (d1ht != d2ht) return false;

    if (d1wd != d2wd) return false;

    if (d1bleed != d2bleed) return false;

    return true;

  }

}())

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2018 Nov 22, 2018
LATEST

I've been searching for something like this for ages. This is great to finally find a script that merges 2 InDesign files on alternate pages (writing this to help with SEO).

Thanks so much again!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 01, 2008 Nov 01, 2008
Hey Dave,

Thank you very much. I will not be able to test it till Monday, as my home machine is a G3, unable to run IDCS3.

Al
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 02, 2008 Nov 02, 2008
Impressive, Dave. Wish I could write scripts as quick as you one day.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines