In CC Illustrator 2023 how do I create a Script to export each layer name as PDF name?
Copy link to clipboard
Copied
Hello Adobe Community,
I have a multi layer Illustrator document and would like to write a script that saves one layer name as an individual PDF. If possible, I would like to be able to select the location where PDF will be saved so I can rewrite existing PDFs in that file path. I found a thread on this topic but the code does not work for me.
Not sure if this is possible but I would like to also have a sepearete script that will also run this for all of the layers so this doesn't have to be repeated for each of the layers.
Any help would be much appreciated!
Explore related tutorials & articles
Copy link to clipboard
Copied
I presume you want each layer saved as different PDFs and not all layers saved as the same PDFs but with different names. The script may be slow running, so test before running on a heavy document.
function main() {
var folder1 = Folder.selectDialog();
var doc1 = app.activeDocument;
for (var i = 0; i < doc1.layers.length; i++) {
app.selection = null;
var layer1 = doc1.layers[i];
layer1.hasSelectedArtwork = true;
var selection = doc1.selection;
var doc2 = app.documents.add();
for (var j = 0; j < selection.length; j++) {
selection[j].duplicate(doc2, ElementPlacement.PLACEATEND);
}
var PDF1 = new PDFSaveOptions();
var name1 = layer1.name;
var file1 = new File(folder1 + "/" + name1);
doc2.saveAs(file1, PDF1);
doc2.close(SaveOptions.DONOTSAVECHANGES);
}
}
main();
Copy link to clipboard
Copied
Hello,
I appreciate the quick response and code but I went ahead and used the code and ran into some issues:
1. it only exports one PDF and resizes it so it does not match original, also the name of the file is different than visible layer??
2. is there a way to always export two layers (LOGO) and (CUT LINES) along with the other PDFs, these two layers do not change and are to be present in all exported PDFs
Attached are a few images that might help.
Thank you!
Copy link to clipboard
Copied
The script was not written with invisible and locked layers in mind. Can you share a test AI file (through a file sharing site)?
Copy link to clipboard
Copied
Hello,
Below is a link to a sample file. If possible, I would like the two lower levels to be visible on the exported PDFs. Untimately it would be nice to run a script that keeps these two levels visible and then export each PDF one by one into a seprate file.
Please see the https://drive.google.com/file/d/1MTni9FLzmXe2FsMDQaKW6m2-soj7JnKG/view?usp=drive_link
Copy link to clipboard
Copied
For anyone interested in a solution. I found a brilliant script written by Matthew Ericson which exports as PDF or PNGs with optional layers visible. All you have to do is download the script and install it into your illustrator scripts library. Example use case.
For more instructions please see this link.

