Copy from Doc1 and paste in Doc2 - in center of page
hello on forums,
i using code below open 'doc1' , paste contents 'doc2'
could please me ensure doc1 pasted center of doc2?
doc2 larger, , objects paste off center, flush left hand side , centrally on y-axis
if there way paste directly center? or if not, move center after pasting?
thank you!
------------------------------------------------
// open bmdfile external doc
var bmdfile = "myfilepath"
app.open(bmdfile);
var doc1 = app.documents[0]; // bmdfile external doc
var doc2 = app.documents[1]; // open blank doc
for(i=0; i<doc1.pages.length; i++)
{
if(doc2.pages.length < i+1){
doc2.pages.add();
}
// group avoid order changing
var myobj = new array;
myobj = app.activewindow.activepage.pageitems;
app.activewindow.activepage.groups.add(myobj);
// duplicate
doc1.pages[i].pageitems.everyitem().duplicate(doc2.pages[i]);
// ungroup
with(app.documents[1]) {
while (groups.length != 0) {
groups.everyitem().ungroup();
}
}
};
// close bmdfile external doc, dont save changes
app.activedocument.close(saveoptions.no);
hi,
use 2nd parameter of method group.duplicate(to, by) ==> array - amount offset new group original group's position.
if y position correct may need use [mx,0] ==> mx different between center of doc2.pages[0] , doc1.pages[0].
i mean
//... var mx = (doc2.pages[0].bounds[3] - doc2.pages[0].bounds[1] ) / 2 - (doc1.pages[0].bounds[3] - doc1.pages[0].bounds[1] ) / 2;
and
//... doc1.pages[i].pageitems.everyitem().duplicate(doc2.pages[i], [mx, 0]);
jarek
More discussions in InDesign Scripting
adobe
Comments
Post a Comment