Skip to main content
Inspiring
June 21, 2022
Answered

Javascript to duplicate pages into other document without creating one large spread

  • June 21, 2022
  • 1 reply
  • 1121 views

Hi all,

In need of guidance, again!

This script duplicates all pages from one doc to another:

var source = app.documents[0]; //first active document
var target = app.documents[1]; //second open document
source.pages.everyItem().duplicate(LocationOptions.AFTER, target.pages.item(-1));

However, it puts all the pages into a long spread after the last page:

 

If I do it manually from within InDesign using Move Pages – 

With the following options:

All Pages

At End of Document

Delete Pages After Moving - OFF

 

This is what the pages look like afterwards (this is what I'm after):

Any ideas how I can overcome this? 

This topic has been closed for replies.
Correct answer JustyR

I think I've fixed it.

Lines 16 to 19 are now:

var myUSDoc = getDocumentByRegex(/-US/g);

if (myUSDoc != undefined)
    app.activeDocument = myUSDoc;

 ...and more importantly, line 33 has changed to this:

source.spreads.everyItem().duplicate(LocationOptions.BEFORE, target.spreads.item(0));

Note it says BEFORE, not AFTER, and item(0) not item(-1). That fixes the problems I was having. Why? I'm not completely sure. But for now, it works.

 

1 reply

brian_p_dts
Community Expert
Community Expert
June 21, 2022

Looks like you don't have Allow Document Spreads to Shuffle selected in the target doc. In that case, just duplicate the spreads: 

var source = app.documents[0]; //first active document
var target = app.documents[1]; //second open document
source.spreads.everyItem().duplicate(LocationOptions.AFTER, target.spreads.item(-1));

 

JustyRAuthor
Inspiring
June 21, 2022

Hi,

 

Thanks for helping. Spreads sorts the multipage issue. Though my next issue is trying to get the alternate layouts separated as per my previous screenshot. 
The script is putting the pages in the other document in reverse order and only one of them shows as an alternate layout. 

JustyRAuthor
Inspiring
June 21, 2022

IGNORE THAT.