#target illustrator var artboardIndex = 1; var artboards = app.activeDocument.artboards; var destFolder = Folder.selectDialog("Select the destination folder"); var destFileName = app.activeDocument.name; var docWidth = prompt("Enter the new document width (in inches):") * 72; var docHeight = prompt("Enter the new document height (in inches):")* 72; // select the objects on the artboard artboards.setActiveArtboardIndex(artboardIndex); app.activeDocument.selectObjectsOnActiveArtboard(); // calculate the scale factor based on the original artboard size var currentArtboard = app.activeDocument.artboards[artboardIndex]; var currentArtboardBounds = currentArtboard.artboardRect; var pastedObjectsWidth = currentArtboardBounds[2] - currentArtboardBounds[0]; var pastedObjectsHeight = currentArtboardBounds[1] - currentArtboardBounds[3]; var scaleFactor = Math.min(docWidth / pastedObjectsWidth, docHeight / pastedObjectsHeight); // copy and paste app.copy(); var newDoc = app.documents.add(DocumentColorSpace.CMYK, docWidth, docHeight); var ABR = newDoc.artboards[0].artboardRect = [0, 0, docWidth, -docHeight]; app.paste(); newDoc.views[0].centerPoint = [docWidth / 2, -docHeight / 2]; // group, re-size and re-position app.executeMenuCommand("group") var pastedObjects = newDoc.selection[0]; pastedObjects.width *= scaleFactor; pastedObjects.height *= scaleFactor; pastedObjects.position = [docWidth / 2 - pastedObjects.width / 2, -docHeight / 2 + pastedObjects.height / 2]; var newFile = new File(destFolder + "/" + destFileName); app.executeMenuCommand("ungroup"); newDoc.saveAs(newFile); newDoc.close();