Copy link to clipboard
Copied
Hello,
I'm trying to create a script to perform the following action
I have been trying to work off an existing script below i found but am having some trouble.
#target illustrator
function test(){
var doc = app.activeDocument;
var parentPath = Folder(File(doc.fullName).parent);
var opts = new PDFSaveOptions();
opts.pDFPreset = "[Smallest File Size]";
doc.saveAs(File(parentPath + "/" + doc.name.replace(/\.\w+$/, "_PREVIEW.pdf")), opts);
};
test();
any help would be appreciated, thank you!
Try this out robomike​
I tried to put in comments to explain each line the best I could.
...#target illustrator-23
// The active document
var doc = app.activeDocument;
// The path of the original document
var originalDocPath = doc.path;
// The name of the original document
var originalDocName = doc.name;
// An array of all the layers in the active document
var allLayers = doc.layers;
// Get just the file name. Ignore the file extension .pdf and .ai
originalDocName = originalDocName.replace(/\.pdf|\.ai/gi, "")
/
Copy link to clipboard
Copied
Hi robomike​,
these snippets should help you out.
2. hide "Info" layer
var IfoLay = doc.layers.getByName("Info");
IfoLay.visible = false;
redraw();
3.1. save as with new name and suffix
doc.saveAs(File(parentPath + "/" + doc.name.replace("_PRINT.ai", "_PREVIEW.pdf")), opts);
If so, have fun
Copy link to clipboard
Copied
Try this out robomike​
I tried to put in comments to explain each line the best I could.
#target illustrator-23
// The active document
var doc = app.activeDocument;
// The path of the original document
var originalDocPath = doc.path;
// The name of the original document
var originalDocName = doc.name;
// An array of all the layers in the active document
var allLayers = doc.layers;
// Get just the file name. Ignore the file extension .pdf and .ai
originalDocName = originalDocName.replace(/\.pdf|\.ai/gi, "")
// Save the active document as a PDF with _PRINT
doc.saveAs(File(originalDocPath + "/" + originalDocName + "_PRINT.pdf"));
// Look through all layers
for (i = 0; i < allLayers.length; i++) {
// Find the layer named INFO
if (allLayers.name == "INFO") {
// Found the layer named INFO. Now turn it off
allLayers.visible = false;
}
// Setup pdf save options
var opts = new PDFSaveOptions();
// Use the preset named Smallest File Size
opts.pDFPreset = "[Smallest File Size]";
// Save the document in the original folder using the original name with the INFO layer off as a PDF with _PREVIEW
doc.saveAs(File(originalDocPath + "/" + originalDocName + "_PREVIEW.pdf"), opts);
}
Copy link to clipboard
Copied
Thank you!
I just tested it and it works, what's interesting is that the section below says it will push out a PDF but it actually creates a AI instead. BUT, the AI file is what i wanted in the first place so it's all good, unless i'm misunderstanding the script.
// Save the active document as a PDF with _PRINT
doc.saveAs(File(originalDocPath + "/" + originalDocName + "_PRINT.pdf"));
really appreciate it!
Copy link to clipboard
Copied
That was my mistake... I intended to save it as an AI file. I would consider using the code snippet that pixxxel schubser​ provided for the info layer part. That will be much more efficient than looping through all the layers like mine. I updated the script correcting my .ai note and file extension... and added in the more efficient layer snippet from pixxxel schubser.
#target illustrator-23
// The active document
var doc = app.activeDocument;
// The path of the original document
var originalDocPath = doc.path;
// The name of the original document
var originalDocName = doc.name;
// Get just the file name. Ignore the file extension .pdf and .ai
originalDocName = originalDocName.replace(/\.pdf|\.ai/gi, "")
// Save the active document as AI with _PRINT
doc.saveAs(File(originalDocPath + "/" + originalDocName + "_PRINT.ai"));
// Get this specific layer
var IfoLay = doc.layers.getByName("INFO");
// Turn it off
IfoLay.visible = false;
// Refresh the artboard
redraw();
// Setup pdf save options
var opts = new PDFSaveOptions();
// Use the preset named Smallest File Size
opts.pDFPreset = "[Smallest File Size]";
// Save the document in the original folder using the original name with the INFO layer off as a PDF with _PREVIEW
doc.saveAs(File(originalDocPath + "/" + originalDocName + "_PREVIEW.pdf"), opts);
Copy link to clipboard
Copied
What is your mothers language?
opts.pDFPreset = "[Smallest File Size]";
Do you have a PDF preset with the exact name [Smallest File Size] ?
Copy link to clipboard
Copied
It's built into the Save Adobe PDF menu for presets out of Illustrator isn't it?
Copy link to clipboard
Copied
Not you subieguy2​
(I meant the mother language of the TO)
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Here is the German version for example