Search code examples
javascriptpdfmethodsduplicatesadobe-illustrator

javascript illustrator copy pdf documents and stack them issue


I'm looking for a way to copy pdf documents and stack them resized (I think resize works as duplicate, so once this works I will be able to complete my script).

I've been using .duplicate for now, and I can only manage to copy 1 item[0] on the same doc. Besides if I copy element by element I won't be able to replace them easily that's why I want to copy the whole document

I'm opening every script I find to understand a possible method.

Syntax is ok

var targetFile = app.documents.add();              //this is my output file - it is created



folder = Folder.myDocuments;                      //this paragraph works for now

sourceFolder = folder.selectDlg("source");

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

 var sourceDoc = app.open(files[i]);

 var doc = app.activeDocument;

 for (l = 0; l < doc.pageItems.length; l++) {  //corrected error

            doc.pageItems[i].selected = true;

}



 var mySel = app.activeDocument.selection;          //this paragraph need rework

 newItem = mySel[0].duplicate(targetFile);            //mysel.duplicate(targetFile) is not a function

// MAIN ERROR

}

I use ESTK and notepad++ and have checked the variable, nothing obviously wrong during F10 debug. Using Jongware's CHM reference guide and some github tutorial but they tend to help for single operation script. My goal is to have script without GUI to reduce errors and time to proceed

Thank you for your time

EDIT: spotted an error with i used two times in a loop


Solution

  • Simple self solution:

    var mySel = app.activeDocument.selection;
    
    app.executeMenuCommand('copy');
    
    targetFile.activate();
    
    newItem = app.executeMenuCommand('paste');