hey @WA_ART this code was taken from Examples scripts provided by Adobe
check out maybe can help you
var selectFile = File.openDialog("select your files", (Multiselect = true));
for (var i = 0; i < selectFile.length; i++) {
var openFiles = app.open(File(selectFile[i]));
}
var cntDocs = app.documents.length;
for (i = 0; i <= cntDocs - 1; i++) {
app.executeMenuCommand("fitin");
try {
// uncomment to suppress Illustrator warning dialogs
// app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
if (app.documents.length > 0) {
var doc = app.activeDocument;
// Get the folder to save the files into
var destFolder = null;
destFolder = doc.path.fsName;
if (destFolder != null) {
var options, i, sourceDoc, targetFile;
// Get the PDF options to be used
options = this.getOptions();
// You can tune these by changing the code in the getOptions() function.
for (i = 0; i < app.documents.length; i++) {
sourceDoc = app.documents[i]; // returns the document object
// Get the file to save the document as pdf into
targetFile = this.getTargetFile(sourceDoc.name, ".pdf", destFolder);
// Save as pdf
sourceDoc.saveAs(targetFile, options);
}
//alert( 'Documents saved as PDF' );
}
} else {
throw new Error("There are no document open!");
}
} catch (e) {
alert(e.message, "Script Alert", true);
}
/** Returns the options to be used for the generated files.
@return PDFSaveOptions object
*/
function getOptions() {
// Create the required options object
var options = new PDFSaveOptions();
// See PDFSaveOptions in the JavaScript Reference for available options
// Set the options you want below:
// For example, uncomment to set the compatibility of the generated pdf to Acrobat 7 (PDF 1.6)
// options.compatibility = PDFCompatibility.ACROBAT7;
// For example, uncomment to view the pdfs in Acrobat after conversion
// options.viewAfterSaving = true;
return options;
}
/** Returns the file to save or export the document into.
@param docName the name of the document
@param ext the extension the file extension to be applied
@param destFolder the output folder
@return File object
*/
function getTargetFile(docName, ext, destFolder) {
var newName = "";
// if name has no dot (and hence no extension),
// just append the extension
if (docName.indexOf(".") < 0) {
newName = docName + ext;
} else {
var dot = docName.lastIndexOf(".");
newName += docName.substring(0, dot);
newName += ext;
}
// Create the file object to save to
var myFile = new File(destFolder + "/" + newName);
// Preflight access rights
if (myFile.open("w")) {
myFile.close();
} else {
throw new Error("Access is denied");
}
return myFile;
}
}
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
for (ii = 0; ii <= cntDocs - 1; ii++) {
app.executeMenuCommand("close");
doc = null;
}