Skip to main content
March 5, 2010
Question

Creating Multi-Page PDF from a Layerd Illustrator file (script)

  • March 5, 2010
  • 1 reply
  • 31365 views

Often times when designing a logo I create different versions and variable options on layers. This can result in several layers in one Illustrator file. Is there an easy way or an existing script that will allow me to (with one click) create a multi-page PDF consisting of all the layers within my .ai file? The current method is turning on each layer, performing a save-as (PDF), then turning off said layer and turning on the next layer and repeating the task and so-on-and-so-forth, etc … It becomes tedious and quite often I save over the previous version, forgetting to re-name it or forget to perform a save on a certain layer. Can anyone help with some advice? I have never written my own script before but am not opposed to trying, where do I begin?

Any help is appreciated.

This topic has been closed for replies.

1 reply

Inspiring
March 5, 2010

You don't say what OS you are using and which scripting language you are thinking of doing this in…

This is a sample that may get you started done in JavaScript so it's platform independent with the exception of my 'mac style' file paths.

If your on a PC it may just be a typo to set to C drive or whatever you call them things…

If you are on the mac OS then it should just dump a load of PDF's on your desktop.

You say about a multi-page PDF but don't think Illustrator can do this unless its been added with multi-artboards in CS4?

Others would have to let you know that…

#target illustrator

var docRef = app.activeDocument;

with (docRef) {

var docName = baseName(name)

var pdfOptions = new PDFSaveOptions();

pdfOptions.pDFPreset = '[High Quality Print]';

// Turn all layers off

for (var i = 0; i < layers.length; i++) {

layers.visible = false;

}

// Turn each layer on

for (var i = 0; i < layers.length; i++) {

if (i == 0) {

layers.visible = true;

redraw();

var layerName = layers.name;

var saveAsPath = new File('~/Desktop/' + docName + '_' + layerName + '.pdf')

saveAs(saveAsPath, pdfOptions);

} else {

layers[i-1].visible = false;

layers.visible = true;

redraw();

var layerName = layers.name;

var saveAsPath = new File('~/Desktop/' + docName + '_' + layerName + '.pdf')

saveAs(saveAsPath, pdfOptions);

}

}

//close(SaveOptions.DONOTSAVECHANGES);

}

function baseName(fileName) {

var nameString = '';

var extOffset = fileName.lastIndexOf('.');

if (extOffset == -1) {

nameString = fileName;

} else {

nameString = fileName.substr(0, extOffset);

}

return nameString;

}

March 5, 2010

Thanks for this. Sorry, I should have mentioned, I am on a Mac. Really what I was looking for was a script that I can load into my scripts folder and re-launch Illustrator, then somehow easily save each layer as a PDF. I can create the multi-page PDF later so that's not a hill to die-on. Your Java script you provided sounds great, but to be honest I have no idea what to do with it. I should have also mentioned, I know nothing about writing scripts or writing code (Java-scripting). I can research it and probably stumble my way through a solution, unless you have an easier recommendation.

Larry G. Schneider
Community Expert
Community Expert
March 6, 2010

Easy enough. Copy the verbage out of post above and paste it into a text editing program (or the ExtendScript Tool Kit if you have it). Save it as SaveLayersToPDF in unformatted text (not RTF) with a .jsx extension. Place the file in Adobe Illustrator CS4 (or 3)>Presets>Scripts. Restart AI. To use the script, just have a file open to process and from File>Scripts select the SaveLayersToPDF.jsx and watch it run.