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

New Here ,
Mar 05, 2010 Mar 05, 2010

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

27.3K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 05, 2010 Mar 05, 2010

Copy link to clipboard

Copied

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;

}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 05, 2010 Mar 05, 2010

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 05, 2010 Mar 05, 2010

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 06, 2010 Mar 06, 2010

Copy link to clipboard

Copied

ExtendScriptToolKit (ESTK) on my version of CS which is the very dated CS2 now is installed by default in the mac 'Utilities' folder in 'Adobe Utilities' folder. Open make new document, paste in as larry has said. The first line '#target illustrator' should let the toolkit know your target app this should be listed top left if it is correct you can check/test the script here by clicking the play button at the top. Illustrator has NO activate/bringToFront() so it may bounce in the dock to run. All being well save out and use as Larry has instructed…

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 06, 2010 Mar 06, 2010

Copy link to clipboard

Copied

Hi Mark,

Script is working really nice.

I am facing two problem in this

1) Separation links are not properly visible in normal view. But in overprint preview no problem. Is there any way to see all the proper image visible in normal view itself.

2) By using so many links my pdf files size are increasing. Is there any way to put low resolution compressed pdf with in 3 mb.

Thanks,

Joe

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 06, 2010 Mar 06, 2010

Copy link to clipboard

Copied

Joe, I have NOT seen anything yet with saving to PDF from any of my apps that allows the setting of a target file size then adjusts the compression/downsampling on the fly to suit (would make a nice app feature). What you need to do is a bit of trial and error. Either find a pre-made PDF preset that suits your needs or make a new one. Once you've got one the just change the string in the script to suit. This line…

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

NOT sure what you mean about 'overprint preview' I have this option permanent in Acrobat.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 09, 2010 Mar 09, 2010

Copy link to clipboard

Copied

Hi Mark,

Couple of weeks ago i raised my query in this title. And after that i got the script format. But still now i dont know how to proceed with this. Can u pls help me. Thanks a million.

Pls refer this title in this forum "Generate Low Resolution pdf script"

--begin script

set PDFpresets to (path to current user folder) & "Library:Application Support:Adobe:Adobe PDF:Settings:" as text
with timeout of 9999 seconds
     list folder PDFpresets without invisibles
     set PDFSetting to choose from list (result) with prompt "Choose PDF Preset:" as string
     if result is false then error number -128
     set NamedPreset to text of PDFSetting as string
     set setName to text 1 thru -12 of NamedPreset
end timeout

tell application "Adobe Illustrator"
     set openPath to file path of document 1 as alias
     set openFile to name of document 1
end tell
tell application "Finder"
     set finalPath to container of openPath as text
     set defaultName to text 1 thru -3 of openFile & "pdf"
end tell
tell application "Adobe Illustrator"
     set finalName to text returned of (display dialog "Last chance to rename the PDF." default answer {defaultName})
     set thePDF to finalPath & finalName
     save current document in thePDF as pdf with options {class:PDF save options, PDF preset:setName}
     close current document saving no
     open openPath
end tell

--end script

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 08, 2010 Mar 08, 2010

Copy link to clipboard

Copied

Mark (and Larry),

I took both of your advice and tried both solutions. Mark, your solution of using the code/script to creat a java script file using ESTK was the most sucessfull. However, it only worked while playing the script in ESTK. It would take each of my layers from the Illustrator file and make a seperate PDF file (that's great and exactly what I'm looking for). Once I saved the Javascript file in ESTK, placed it into the Scripts folder for AI, and restarted the program, went to File> Scripts and tried to execute said script on my open file, I got this error:

Picture 3.png

Now, I'm no Bill Joy, but I'm guessing it has something to do with errant formatting in the code. I copy and pasted the code from your post, pasted it into "Text Edit", making sure to select "Make plain text" before pasting, then copied and pasted into ESTK. Judging from the Chinese characters in the error dialog box, something is amiss. Any insight as to what I'm doing wrong? Recieved the same Syntax error with your solution and Larry's solution of simply saving into "Text Edit" with a .jsx extension, so it must be something I'm picking up from the code correct?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 08, 2010 Mar 08, 2010

Copy link to clipboard

Copied

I don't know what's gone on there. Im now at work and have been able to cut & paste the posted code straight out of the forum into ESTK save as straight into Illustrator's script location and run (with doc open it does NO tests for this) worked just fine?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 08, 2010 Mar 08, 2010

Copy link to clipboard

Copied

Mark,

Well, I said I was no Bill Joy and that's quite evident. I might have misspoken earlier when I said I copied your code from the forum directly. What I actually copied from was the email notification I originally recieved (your initial response) and pasted that into TextEdit, etc … There-in lies the problem. I went back to your original post on the forum and started over, and viola, problem solved. I want to thank you for posting this answer and for sticking with this "newbie" to the scripting world. This solution is exactly what I was after and will save me countless moments of mind-numbing saving of PDF's in the future. Pat yourself of the back, Mark.

Thanks again.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 16, 2014 Jan 16, 2014

Copy link to clipboard

Copied

Hi Mark,

The script works really well. Except one thing. When I open the PDF in Illustrator it has all the layers in it.

Is there a way to have the hidden layers removed before saving as PDF? As the file size becomes way heavier than expected.

Bless,

Fred

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 21, 2014 Jan 21, 2014

Copy link to clipboard

Copied

var idoc = app.activeDocument;

//loop through all layers deleting hidden layers. Loop from the back, to preserve index of remaining layers when we remove one.

var layerCount = idoc.layers.length;

for (var i = layerCount - 1; i >= 0; i--) {

          var thisLayer = idoc.layers;

          if (thisLayer.visible == false || thisLayer.locked == true) {

                    thisLayer.visible = true;

                    thisLayer.locked = false;

                    thisLayer.remove();

          }

}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 29, 2022 Apr 29, 2022

Copy link to clipboard

Copied

LATEST

hello,
on search for making seperate layers out of pdf's, i stumbled upon this amazing script.
thank you so much!
my question;
i've pdf's where are no layers but many things over each other. when i open them it looks like a video.
is it somehow possible to seperate all this elements? ..fo later make a video out of this image sequence...
my file layer looks like this (see encl.)
thank you!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines