Hi,
I’m trying to save different layers of an illustrator document in pdf format but i don’t find solution:/
what i want :
saving all the layers of my illustrator document in individual pdf files
it 's possible or not ?
in fact, would like to do the same thing to CAD TOOL MULTIPAGE : http://www.hotdoor.com/
thanks
JP
JP,
You could hide the layers you’re not interested in and save from there (possibly) or make a new document and paste everything from a particular layer to the new document and then save as pdf.
PreTech
Well, after posting this, I tried to save as pdf, but aparently the pdf must exist already:rolleyes: Unless someone else has a way to save to pdf that I’m unaware of. You could print to post script, however it will alway default to 8.5 inch by 11 inch page (Do a search for CalvinFold(user). There were a lot of attempts at printing to postscript and then distilling to pdf but they all ended up 8.5 x 11). This is all in Illustrator CS. I just recently got CS2 but haven’t tried any of this with it yet.
thanks PreTech
but i’m waiting for an other solution
print to ps & distill will result in flat pdf and may not be what is wanted.
perhaps but i don’t know coding that in applescript ?
PreTech, what issue are you having with save as to pdf? I’ve dug out a basic script that I did a while ago now. Save as to PDF has not been a problem. What I do get is that the save as appears to only be allowed the once in file which is a pain in the A$$ error -43 file not found. If you just turn the layers visible off its contents will remain in the pdf. They can be turned back on in both Acrobat 6 and illustrator. In photoshop I would be able to save a history state before removing layers then save then step back to history state but I find no similar feature in illustrator to remove the layers permanently seams to require opening the file several times over. I could well be missing a lot here only just started to play with this app again. here is a clumsy effort.
set Savefolder to choose folder with prompt "Where do you want to save the Files?"
set MyFile to choose file with prompt "Find your layered file" without invisibles
tell application "Finder"
set MyFile to MyFile as alias
end tell
--
tell application "Illustrator CS"
activate
open MyFile
set docRef to the current document
tell docRef
set MyLayers to count of layers
set visible of layer 1 to true
set LayerName to name of layer 1 as string
delete (every layer whose name is not LayerName)
set docName to name of docRef
set docBaseName to getBaseName(docName) of me
set newFileName to (Savefolder as string) & docBaseName & "-" & LayerName & ".pdf"
save docRef in file newFileName as pdf with options ¬
{class:PDF save options, acrobat layers:true, changes allowed:pdf 128 any changes, color compression:automatic JPEG high, color downsampling:300, color downsampling threshold:450, color resample:bicubic downsample, compatibility:Acrobat 5, compress art:true, embed ICC profile:false, enable access:true, enable copy:true, enable copy and access:true, font subset threshold:100.0, generate thumbnails:true, grayscale compression:automatic JPEG high, grayscale downsampling:300, grayscale downsampling threshold:300, grayscale resample:bicubic downsample, monochrome compression:CCIT4, monochrome downsampling:300, monochrome downsampling threshold:450, monochrome resample:bicubic downsample, optimization:true, preserve editability:true, printer resolution:1200, registration marks:false, view pdf:false}
close docRef without saving
end tell
end tell
--
repeat with i from 2 to MyLayers
tell application "Illustrator CS"
open MyFile
set docRef to the current document
tell docRef
set LayerName to name of layer i as string
delete (every layer whose name is not LayerName)
set docName to name of docRef
set docBaseName to getBaseName(docName) of me
set newFileName to (Savefolder as string) & docBaseName & "-" & LayerName & ".pdf"
save docRef in file newFileName as pdf with options ¬
{class:PDF save options, acrobat layers:true, changes allowed:pdf 128 any changes, color compression:automatic JPEG high, color downsampling:300, color downsampling threshold:450, color resample:bicubic downsample, compatibility:Acrobat 5, compress art:true, embed ICC profile:false, enable access:true, enable copy:true, enable copy and access:true, font subset threshold:100.0, generate thumbnails:true, grayscale compression:automatic JPEG high, grayscale downsampling:300, grayscale downsampling threshold:300, grayscale resample:bicubic downsample, monochrome compression:CCIT4, monochrome downsampling:300, monochrome downsampling threshold:450, monochrome resample:bicubic downsample, optimization:true, preserve editability:true, printer resolution:1200, registration marks:false, view pdf:false}
close docRef without saving
end tell
end tell
end repeat
--
on getBaseName(fName)
set baseName to fName
repeat with idx from 1 to (length of fName)
if (item idx of fName = ".") then
set baseName to (items 1 thru (idx - 1) of fName) as string
exit repeat
end if
end repeat
return baseName
end getBaseName
ooops c&p missed again. and i’ve not even been to the pub yet.
it’s not running sorry
message : Impossible d’obtenir document 1 ?
Hi Jean
Don’t think there’s a neat and tidy way of doing this, But would imagine it can be done.
here’s something cobbled together from a script in the adobe illustrator scripting guide and a bit i’ve
added (Not Much!) its not gonna do everything you want didn’t have time to put all the pieces together but
it should set you off in the right directions, if i get chance i will add the rest over the weekend.
tell application "Illustrator CS"
if not frontmost then activate
if (count documents) > 0 then
tell current document
set selection to every page item of layer 1
delay 0.2
end tell
set selectedItems to selection of current document
if selectedItems is not {} then
copy
set colorSpace to color space of current document
tell current document to delete current layer
make new document with properties {color space:colorSpace}
paste
end if
end if
end tell
You will need to add a repeat loop if your processing multiple documents and you will have to add the save as pdf bit.
but this will select everything on a layer then copy it to a new document, at this point you will want to save as a pdf then close.
that layer will have been deleted from the original document so this is where you will pick up the items on the next layer and so on and on .
F.A.O. Mark67
Hey mark i posted on the same thread has Pretech and Calvinford regarding having trouble with saving has pdf.
i think the trouble Calvin was having is the quality of the pdf that illustrator creates don’t think it goes thru is rip or devices where he works
that well. he was trying to print a pdf via “AdobePDF 7.0” he was getting a better quality pdf he could work with.
However! Myself, Pretech and Calvinford all had similar trouble with getting a pdf out this way that wasn’t cropped down to roughly A4.
it WAS very frustrating.
I say WAS because lately myself and a colleague at work have had some promising results printing to pdf via illustrator print dialog, I’m currently on with a script which hopefully will resolve this issue but its not finished need to iron out a few kinks, but will be posting it if and when i sort it…
thanks pidge1
i’ll try but i don’t understand why we can’t find a simplest solution
it took me some time to figure it out but I have a good solution you may want to set some options for the save as pdf thats up to you and you could change the names of the save file . you will have to set up a routine to pass a file alias into this routine
on SaveLayersToPDF(afile)
tell application "Adobe Illustrator"
activate
open afile
tell document 1
repeat with i from 1 to (count of layers)
set visible of every layer to false
set visible of layer i to true
set NameOfLayer to name of layer i
set selection to every page item of layer i
-- you must group the everything on the layer to get the bounds of the objects
-- doing this does have the potential to have adverse effects
tell application "System Events"
keystroke "g" using command down
end tell
set sHeight to height of selection
set sWidth to width of selection
tell application "System Events"
keystroke "p" using {command down, option down}
keystroke tab
keystroke ("" & (sWidth + 5.0) & "pt")
keystroke tab
keystroke ("" & (sHeight + 5.0) & "pt")
keystroke return
end tell
set ROx to ((get width) / 2)
set ROy to ((get height) / 2)
set ruler origin to {ROx, ROy}
set position of selection to {-ROx + 2.5, ROy - 2.5}
save in ("" & ((path to current user folder) & ":Desktop:" & NameOfLayer)) as pdf
end repeat
end tell
close document 1
end tell
end SaveLayersToPDF
Mark67,
Well, holly heck darn! There must have been something else wrong with my hurry up code when first I posted (I was just trying to save to pdf and I don’t remember what the code was 'cause I didn’t save it) because it kept telling me that it couldn’t find the file to save into (the infamous -43 error).
The following code worked just fine with Illustrator CS2 but will not work with CS without giving the -43 error. As you say, the document in CS may have to be opened several times. The following code was a result of many attempts to get it to work with CS and of course doesn’t have to have the subroutine (that’s just the way I ended).
set whereTo to path to desktop as string
tell application "Adobe Illustrator"
set fileName to "ill.pdf"
set t to make new document
tell t
make new layer after layer "Layer 1" with properties {name:"myLayer 2"}
make new rectangle in layer "Layer 1" with properties {name:"s1", position:{50, 550}, height:100, width:300, fill color:{class:CMYK color info, black:100}}
make new rectangle in layer "myLayer 2" with properties {name:"s2", position:{95, 400}, height:300, width:25, fill color:{class:CMYK color info, cyan:0, magenta:75, yellow:100, black:5}}
end tell
set c to count every layer of t
repeat with y from 1 to c
set lName to name of layer y of t
set thePath to whereTo & lName & fileName
my layerVis(thePath, lName)
end repeat
end tell
on layerVis(thePath, lName)
tell application "Adobe Illustrator"
set x to current document
set visible of every layer of x whose name is not lName to false
set visible of layer lName of x to true
save x in file thePath as pdf with options {class:PDF save options, compatibility:Acrobat 5}
end tell
end layerVis
jeanphilippe, if you’re using Illustrator CS, you may have to use mark67’s solution to repeatedly open and close the document to get each layer to save to pdf.
Sorry for my lateness.
PreTech
PreTech,
Did I miss something in my last post or does that now work with CS ? also your solution does not deal with the size of the resulting PDF.
mcgrailm
mcgrailm,
Your script doesn’t seem to work with CS. It gives the same -43 error which is what I had problems with the first time I saw this post.
In as far as the size of the page, the resulting pdf from the script I posted using CS2 will be the same size as the document because it is saving the document as a pdf from Illustrator CS2. (Or at least it is here.)
The following script seems to duplicate everything to the same spot in a new document and save to pdf in CS. Of course I have been having Illustrator make new documents to copy from as opposed to opening a file, but that should also be no problem.
set whereTo to path to desktop as string
tell application "Illustrator CS"
activate
set t to make new document with properties {height:864, width:864}
tell t
make new layer with properties {name:"newLayer 2"}
make new rectangle in layer "Layer 1" with properties {position:{100, 200}, height:84, width:500}
make new ellipse in layer "newLayer 2" with properties {name:"e1", position:{45, 752}, height:75, width:150, fill color:{class:CMYK color info, cyan:0, magenta:100, yellow:50, black:0}}
end tell
set theSize to {{}, {}}
set item 1 of theSize to height of t
set item 2 of theSize to width of t
set docName to name of current document
repeat with i from 1 to (count every layer of t)
set lName to name of layer i of document docName
set thePath to whereTo & lName & ".pdf"
set k to make new document with properties {height:(item 1 of theSize), width:(item 2 of theSize)}
set visible of every layer of document docName to false
set visible of layer i of document docName to true
repeat with j from 1 to (count every layer of document docName)
if visible of layer j of document docName is true then
set selection to every page item of layer j of document docName
exit repeat
end if
end repeat
duplicate selection of document docName to k
save k in file thePath as pdf with options {class:PDF save options, compatibility:Acrobat 5}
close current document saving no
end repeat
end tell
PreTech
thanks all !
but i’ve a error message : Can’t find document 1
i use CS2 10.0.1 and french version
if your using my script you must pass the routine the full file path as alias
if you just want to test it first open the a file then run this script
tell application "Adobe Illustrator"
activate
tell document 1
repeat with i from 1 to (count of layers)
set visible of every layer to false
set visible of layer i to true
set NameOfLayer to name of layer i
set selection to every page item of layer i
-- you must group the everything on the layer to get the bounds of the objects
-- doing this does have the potential to have adverse effects
tell application "System Events"
keystroke "g" using command down
end tell
set sHeight to height of selection
set sWidth to width of selection
tell application "System Events"
keystroke "p" using {command down, option down}
keystroke tab
keystroke ("" & (sWidth + 5.0) & "pt")
keystroke tab
keystroke ("" & (sHeight + 5.0) & "pt")
keystroke return
end tell
set ROx to ((get width) / 2)
set ROy to ((get height) / 2)
set ruler origin to {ROx, ROy}
set position of selection to {-ROx + 2.5, ROy - 2.5}
save in ("" & ((path to current user folder) & ":Desktop:" & NameOfLayer)) as pdf
end repeat
end tell
close document 1
end tell
jeanphilippe,
It may be beneficial to all if you post the code you are using so we can see what is going on when your script errs.
PreTech
excellent tha’t run ! thanks mcgrailm
but i must group elements on each layer if i want to preserve my artwork intact:)
yes, sorry PreTech, you are right
here is slight variation that perservese the integrity of the artwork by undoing the grouping after we get the bounds of the group.
on SaveLayersToPDF(afile)
tell application "Adobe Illustrator"
activate
open afile
tell document 1
repeat with i from 1 to (count of layers)
set visible of every layer to false
set visible of layer i to true
set NameOfLayer to name of layer i
set selection to every page item of layer i
-- you must group the everything on the layer to get the bounds of the objects
tell application "System Events"
tell process "Adobe Illustrator CS2"
click menu item "Group" of menu "Object" of menu bar 1
end tell
end tell
set sHeight to height of selection
set sWidth to width of selection
tell application "System Events"
--undoing the grouping will perserve your artwork
keystroke "z" using command down
keystroke "p" using {command down, option down}
keystroke tab
keystroke ("" & (sWidth + 5.0) & "pt")
keystroke tab
keystroke ("" & (sHeight + 5.0) & "pt")
keystroke return
end tell
set ROx to ((get width) / 2)
set ROy to ((get height) / 2)
set ruler origin to {ROx, ROy}
set position of selection to {-ROx + 2.5, ROy - 2.5}
save in ("" & ((path to current user folder) & ":Desktop:" & NameOfLayer)) as pdf
end repeat
end tell
close document 1 without saving
end tell
end SaveLayersToPDF
please disregard my last post that doesn’t work it simple undos the move unfortunately I have not been able to find another way to get the bounds of all the objects on the layer in any other way
mcgrailm,
I’m not sure you have to go to all this trouble to get the positioning of all the items. If you make a new document with the current document size and then duplicate the items to the new document, they are already in the same position.
PreTech