Move/duplicate pages between documents
Like you probably know, InDesign can move/duplicate pages within document through scripting, but you can also move/duplicate pages between documents! I found this snippet on Adobe’s InDesign scripting forum, and I tested it and it works just fine!😀
First, we have to declare source and destination documents:
var source_doc = app.documents.item('myTestDoc1.indd'); var destination_doc = app.documents.item('myTestDoc2.indd');
Good, now we have document variables, so, let’s select page we want to move/duplicate.
var sourcePages = source_doc.pages.item(0);
Ok, now ‘sourcePages’ now contains just one page, but what if we want to move/duplicate more than one pages. In that case, we can use itemByRange(); like this:
var sourcePages = source_doc.pages.itemByRange(0,1);
Now we selected page one and page two. Good, now, let’s see first how to move pages to other document.
This is little different than moving pages within document because we must set destination document, but ‘.move();’ method reference parameter accepts just page or spread, so we have to pass destination document with destination page like you see in code. In this case, page from source document will be moved to destination document before first page. If you want to move page at the end of destination document you can do this:
Also, if you want, you can set binding parameter in move method like this:
sourcePages.move(LocationOptions.BEFORE, destination_doc.pages.item(0), BindingOptions.RIGHT_ALIGN);
Good, now let’s duplicate page from one document to another:
Again, sourcePages can be single page or multi page. Important thing is that ‘.duplicate();’ method doesn’t have binding parameter!
Yeah, that’s it!