Copy link to clipboard
Copied
I currently have a working script for SaveDocsAsPDF_Presets and it works great, but now that we can Save a Copy instead of Save As in Illustrator, I was hoping someone could modify my script to be Save a Copy instead of Save As? I don't know how to write scripts and my feeble attempt to modify it has resulted in no results...any help apprecitated!
Here is my current script (also attached .txt file):
var w = new Window("dialog", "Choose a Preset");
var dropdownlist = w.add("dropdownlist", undefined, app.PDFPresetsList);
dropdownlist.preferredSize.width = 200;
dropdownlist.selection = 0;
var choice = dropdownlist.selection;
dropdownlist.onChange = function () {
choice = dropdownlist.selection;
};
var button = w.add("button", undefined, "OK");
button.onClick = function () {
saveDocsAsPDF(choice);
w.close();
};
w.show();
function saveDocsAsPDF(choice) {
// original SaveDocsAsPDF script
try {
if (app.documents.length > 0 ) {
var destFolder = null;
destFolder = Folder.selectDialog('Select folder for PDF files.', '~');
if (destFolder != null) {
var options, i, sourceDoc, targetFile;
options = getOptions();
for ( i = 0; i < app.documents.length; i++ ) {
sourceDoc = app.documents[i];
targetFile = getTargetFile(sourceDoc.name, '.pdf', destFolder);
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);
}
function getOptions() {
var options = new PDFSaveOptions();
options.pDFPreset = choice;
return options;
}
function getTargetFile(docName, ext, destFolder) {
var newName = "";
if (docName.indexOf('.') < 0) {
newName = docName + ext;
} else {
var dot = docName.lastIndexOf('.');
newName += docName.substring(0, dot);
newName += ext;
}
var myFile = new File( destFolder + '/' + newName );
if (myFile.open("w")) {
myFile.close();
}
else {
throw new Error('Access is denied');
}
return myFile;
}
}
Hello Rene, thanks for responding!
Is this how the end script should look?
var w = new Window("dialog", "Choose a Preset");
var dropdownlist = w.add("dropdownlist", undefined, app.PDFPresetsList);
dropdownlist.preferredSize.width = 200;
dropdownlist.selection = 0;
var choice = dropdownlist.selection;
dropdownlist.onChange = function () {
choice = dropdownlist.selection;
};
var button = w.add("button", undefined, "OK");
button.onClick = function () {
saveDocsAsPDF(ch
...Bonjour Emac,
Sa vous donne satisfaction?
Il manque juste l'étape 1:
1 inverser deux lignes pour fermer la boîte de dialogue plus rapidement.
Il est préférable de fermer la boîte de dialogue W avant le traitement autrement c'est perturbant (pour moi).
// ----------------------------
button.onClick = function() {
w.close();
saveDocsAsPDF(choice);
};
// ---------------------------
Copy link to clipboard
Copied
Was hoping for at least some comments on this post by now. Does anyone know if this is possible to do with Scripts?
Copy link to clipboard
Copied
If the purpose is not to save changes to the first file, you can just save a second file under another name. I've added a line (line 46) that adds the word "Copy" to the second file.
var w = new Window("dialog", "Choose a Preset");
var dropdownlist = w.add("dropdownlist", undefined, app.PDFPresetsList);
dropdownlist.preferredSize.width = 200;
dropdownlist.selection = 0;
var choice = dropdownlist.selection;
dropdownlist.onChange = function() {
choice = dropdownlist.selection;
};
var button = w.add("button", undefined, "OK");
button.onClick = function() {
saveDocsAsPDF(choice);
w.close();
};
w.show();
function saveDocsAsPDF(choice) {
// original SaveDocsAsPDF script
try {
if (app.documents.length > 0) {
var destFolder = null;
destFolder = Folder.selectDialog('Select folder for PDF files.', '~');
if (destFolder != null) {
var options, i, sourceDoc, targetFile;
options = getOptions();
for (i = 0; i < app.documents.length; i++) {
sourceDoc = app.documents[i];
targetFile = getTargetFile(sourceDoc.name, '.pdf', destFolder);
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);
}
function getOptions() {
var options = new PDFSaveOptions();
options.pDFPreset = choice;
return options;
}
function getTargetFile(docName, ext, destFolder) {
ext = " - Copy" + ext;
var newName = "";
if (docName.indexOf('.') < 0) {
newName = docName + ext;
} else {
var dot = docName.lastIndexOf('.');
newName += docName.substring(0, dot);
newName += ext;
}
var myFile = new File(destFolder + '/' + newName);
if (myFile.open("w")) {
myFile.close();
} else {
throw new Error('Access is denied');
}
return myFile;
}
}
Copy link to clipboard
Copied
Thank you for replying @femkeblanco!
Unfortunately, that is not the way I wanted to use this function. I use the Save a Copy feature to save .pdf versions of .ai files, but I still want the open .ai files (multiple tabs usually for this script) to remain .ai files until I'm sure the .pdf versions are correct after a double check. I always keep & save the original artwork / file as an .ai file, but make smaller data .pdf file versions of proofs for emailing to clients and general viewing by people who don't have Illustrator. I know anyone can view an .ai file if they have a .pdf viewer, but .pdf's are just better for sharing.
When I use the current script (original one I had), it saves the open tabs / files as .pdf's using my presets like I want, but it changes all my currently open tabs to .pdf files and if I have to make changes after viewing the .pdfs, I have to do a Save As to get them back to .ai files.
So what I'm looking for is to Save a Copy of all of the currently open tabs / files in Illustrator at once as .pdf's using my presets, but I would like the currently open tabs / files in Illustrator to remain .ai files. It would also be most benificial not to have the tag of "copy" at the end of each of the new .pdf files as well. This is because there are not really copies, just the same files as bounced down .pdf's.
I hope this makes sense and is possible! Any help is appreciated!
Copy link to clipboard
Copied
Bonjour 'Emac',
Je te propose d'apporter deux modifications à ton script.
1 inverser deux lignes pour fermer la boîte de dialogue plus rapidement.
button.onClick = function() {
w.close();
saveDocsAsPDF(choice);
};
2 Le bloc if (destFolder != null) { doit devenir ce qui suit:
if (destFolder != null) {
var options, i, sourceDoc, targetFile, liste = [];;
options = getOptions();
options.viewAfterSaving = false;
for (i = app.documents.length-1; i >= 0; i--) {
sourceDoc = app.documents[i];
liste.push(sourceDoc.fullName);
targetFile = getTargetFile(sourceDoc.name, '.pdf', destFolder);
sourceDoc.saveAs(targetFile, options);
sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
}
for (var i = 0; i < liste.length;i++) {
app.open(new File(liste[i]));
}
alert(i+' Documents saved as PDF');
}
Cordialement René
Copy link to clipboard
Copied
Hello Rene, thanks for responding!
Is this how the end script should look?
var w = new Window("dialog", "Choose a Preset");
var dropdownlist = w.add("dropdownlist", undefined, app.PDFPresetsList);
dropdownlist.preferredSize.width = 200;
dropdownlist.selection = 0;
var choice = dropdownlist.selection;
dropdownlist.onChange = function () {
choice = dropdownlist.selection;
};
var button = w.add("button", undefined, "OK");
button.onClick = function () {
saveDocsAsPDF(choice);
w.close();
};
w.show();
function saveDocsAsPDF(choice) {
// original SaveDocsAsPDF script
try {
if (app.documents.length > 0 ) {
var destFolder = null;
destFolder = Folder.selectDialog('Select folder for PDF files.', '~');
if (destFolder != null) {
var options, i, sourceDoc, targetFile, liste = [];;
options = getOptions();
options.viewAfterSaving = false;
for (i = app.documents.length-1; i >= 0; i--) {
sourceDoc = app.documents[i];
liste.push(sourceDoc.fullName);
targetFile = getTargetFile(sourceDoc.name, '.pdf', destFolder);
sourceDoc.saveAs(targetFile, options);
sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
}
for (var i = 0; i < liste.length;i++) {
app.open(new File(liste[i]));
}
alert(i+' Documents saved as PDF');
}
} else {
throw new Error('There are no document open!');
}
} catch(e) {
alert( e.message, "Script Alert", true);
}
function getOptions() {
var options = new PDFSaveOptions();
options.pDFPreset = choice;
return options;
}
function getTargetFile(docName, ext, destFolder) {
var newName = "";
if (docName.indexOf('.') < 0) {
newName = docName + ext;
} else {
var dot = docName.lastIndexOf('.');
newName += docName.substring(0, dot);
newName += ext;
}
var myFile = new File( destFolder + '/' + newName );
if (myFile.open("w")) {
myFile.close();
}
else {
throw new Error('Access is denied');
}
return myFile;
}
}
Copy link to clipboard
Copied
Bonjour Emac,
Sa vous donne satisfaction?
Il manque juste l'étape 1:
1 inverser deux lignes pour fermer la boîte de dialogue plus rapidement.
Il est préférable de fermer la boîte de dialogue W avant le traitement autrement c'est perturbant (pour moi).
// ----------------------------
button.onClick = function() {
w.close();
saveDocsAsPDF(choice);
};
// ---------------------------
Copy link to clipboard
Copied
Bonjour René! Ouais, cela semble fonctionner dans les deux cas, mais je l'ai modifié par ce que vous avez suggéré, merci beaucoup!