Many a folk on these boards have tried to tackle the elusive scripting of Adobe products to create consitent PDFs.
You ask, “They tried and failed?”
I answer, “They tried and died.”
-extra points for naming the movie quote
However, for my specific purposes, I’m pretty close to accomplishing my goal. I’m trying to drop a folder containing Illustrator files onto a droplet script and have the script create PDFs of every Illustrator file. My chosen poison has been to “print PDFs” to “Adobe PDF 7.0” which results in a small and, from my experience, reliable PDF. Only catch is that the “print PDFs” method only creates 8.5"x11" PDFs, as many on this site can attest. So, I decided to have the script “print PDFs” of 8.5"x11" documents and “save as” documents of other sizes.
This works well for me except that my current scripting of “save as” to PDF tends to create VERY LARGE PDFs. (I am trying to create PDFs that are a reasonable size, 100kb to 4mb, so that they are feasible for email.) When I manually use the “smallest file size” under “save as” I can get a reasonable size PDF from a 100mb Illustrator file but I can’t script this yet. I can show you “smallest file size” in the Illustrator scripting dictionary but I can’t access it through scripting. Maybe you know how?
Can anyone offer any help? I assume that GUI scripting may be the way to go but I haven’t done much GUI scripting beyond the very basics. I appreciate any suggestions, including correcting any inefficiencies I have in the current script that are unrelated to my “issue”.
Thanks for your time!
Here is the basic “working” script that creates great PDFs from 8.5"x11" Illustrator CS2 documents and VERY LARGE & UNRULY PDFs from large documents (100mb) that are sizes other than 8.5"x11".
on open {input_folder}
set openDay to short date string of (current date)
set openTime to time of (current date)
tell application "Finder"
try -- This creates the new folder.
make new folder with properties {name:"Print_n_Save"} at desktop
end try
copy the result to NEWfolder
move contents of input_folder to NEWfolder
--This moves the droped files to the newly created folder.
try
set desktopPDFs to (every file of desktop whose kind is "Adobe PDF document") as alias list
on error -- happens if there is only one
set desktopPDFs to (every file of desktop whose kind is "Adobe PDF document") as alias as list
end try
set PDF_count to the count of desktopPDFs --This variable is the number of PDFs already on the desktop.
try
set input_files to (every file of entire contents of input_folder whose kind is "Adobe Illustrator Document") as alias list
on error -- happens if there is only one
set input_files to (every item of entire contents of input_folder whose kind is "Adobe Illustrator Document") as alias as list
end try
set newPDF_count to the count of input_files --This variable is the number of new PDFs that are about to be printed.
set theDesktop to desktop as string
tell application "Adobe Illustrator" --This section"prints" every Illustrator file.
activate
set printToAcrobat to {class:print options, printer name:"Adobe PDF 7.0"}
set saveToPDF to {class:PDF save options, compatibility:Acrobat 5, preserve editability:false, compress art:true, optimization:true} --, PDF preset:Smallest File Size?
repeat with currentFile in input_files
open currentFile
set x to width of current document
set y to height of current document
set thewidth to x div 2.834645 as integer
set theheight to y div 2.834645 as integer
if thewidth is in {215, 279} and theheight is in {215, 279} then
try
print current document options printToAcrobat
end try
else
set theName to name of current document as string
save current document in file (theDesktop & theName) as pdf with options saveToPDF
end if
close current document saving no
end repeat
end tell
set wait to true --This section delays the script until the PDFs are all "printed" or created.
repeat while wait is true
tell application "Finder"
try
set latestDesktop to (every file of desktop whose kind is "Adobe PDF document") as alias list
on error -- happens if there is only one
set latestDesktop to (every file of desktop whose kind is "Adobe PDF document") as alias as list
end try
set latestPDF_count to the count of latestDesktop
if latestPDF_count is less than (newPDF_count + PDF_count) then
delay 2
else
set wait to false
end if
end tell
end repeat
try --This section finds the "printed" PDFs at the desktop, removes the ".ai" and moves the files to the new folder.
set allPDFs to (every item of desktop whose kind is "Adobe PDF document") as alias list
on error
set allPDFs to (every item of desktop whose kind is "Adobe PDF document") as alias as list
end try
repeat with aPDF in allPDFs
set createdate to creation date of aPDF
set createday to short date string of createdate
set createTime to time of createdate
if createday = openDay and createTime is greater than openTime then
set theName to name of aPDF
set TID to " "
set AppleScript's text item delimiters to ".ai"
set newParts to (text items of theName)
set AppleScript's text item delimiters to ""
set name of aPDF to newParts as string
set AppleScript's text item delimiters to TID
move aPDF to NEWfolder
end if
end repeat
end tell
end open
After taking a quick look, I don’t see anywhere in your script where you set the page size in the printer prefs.
There was an earlier post with a similar InDesign question, and the answer seemed straight forward if you refer to the Scripting documentation that Adobe provides.
in this case we save pdfs from layers. the easiest way I have seen to get the pdf to the size you want is to make a new document the size that you want and put the content on it then center it then run your print routine
as far as file size you may want to first ensure that you remove all unused brushes graphic styles etc. you can do that via action (in default set) addtionally you may runnning the resulting PDFs through the automator workflow Save As PDF-X
-- Paper Sizes
--
-- Make a new documet
-- Get the name of printer 1
-- Get the paper sizes of printer 1
-- For each paper size, get the name and height/width
-- Display the printer info
--
tell application "Illustrator CS"
activate
make new document
set printerName to (name of item 1 of printers) as string
set printerProperties to properties of (get properties of item 1 of printers)
set paperSizes to paper sizes of printerProperties
set textContents to printerName & return & "Paper Sizes:" & return
repeat with paperSize in paperSizes
set paperName to name of paperSize
set paperHeight to height of properties of paperSize
set paperWidth to width of properties of paperSize
set textContents to textContents & tab & paperName & " - (" & paperHeight & "
x " & paperWidth & ")" & return as string
end repeat
make new text frame in document 1 with properties {contents:textContents, position:{20, 600}}
end tell
Just change the numbers to get the next one in the list in your print set-up utility.
or for what ever your adobe pdf 7.0 is…
This will give you the list of available papersizes… it doesn’t give you the custom paper option that you get in the print dialog (dam!) check previous posts for what a god forsaking thing this is…
However you can get all the papersizes that it says in the list. so if it’s a standard size like A4,A3, even upto A0 which i think is the biggest you can acheive…
unfortunatley if your like me and you print to machines which use sheets as big as 2.6 metres then its not the best but if you can live with the standard sizes your laughing…
OK, OK. Lots to think on here. Thanks for the responses. Let me sort through this…
First of all, although it is possible to “print to Adobe PDF 7.0” other sizes besides 8.5"x11", I need to create PDFs at custom sizes and some of those sizes are larger than the largest PDF that “Adobe PDF 7.0” can print to. (Based on the script that pidge1 gave me, I found that 92"x92" is the largest.)
It seems to me that scripting all the possible scenerios that are required by the custom size documents I work with would be the more complicated approach and in some cases, documents larger than 92"x92", impossible. This is why I have elected to “Save as” documents that are other than the default 8.5"x11" size. Does this make sense? No one has addressed this line of thinking that I suggested.
While I think this is the best approach, I do need help to figure out how to use the “PDF Preset: Smallest File Size” setting. Can anyone offer some guidance? I think it is there to use but I just don’t know how to script it. That is why I suggested GUI scripting. (On that note, can anyone atleast give me some pointers or direct me to a detailed post or resource on GUI scripting?)
Also, HarryCarey, I’m a little confused. Is They Tried to Outlaw Christmas a movie? If so, when was it made?
again here is the code from the thread I had pointed out
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
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
end tell
copy selection
tell application "Adobe Illustrator"
make new document with properties {height:(sHeight + 5.0), width:(sWidth + 5.0)}
end tell
paste
save in ("" & ((path to current user folder) & ":Desktop:" & NameOfLayer & ".pdf")) as pdf
tell application "Adobe Illustrator"
close document 1 without saving
end tell
end repeat
end tell
close document 1 without saving
end tell
and if your clever this is a way to do this with out the copy paste
all you have to do is instead of doing this for each layer do it for the whole doc
for this
find the workfloow and open it see what it does and make your own version that doesn’t ask where to save it then save your version as an app
in your applescript have the new " workflow.app" open the files this will process them
I don’t mean to be rude “mcgrailm” but did you read my post?
I appreciate you pointing me to this script but it doesn’t even address my issue. Creating new documents at different sizes doesn’t help me. I have absolutely no problems creating PDFs from Illustrator CS2 with the “save in…” command. Did you see my original post? It uses “save in…” to successfully create PDFs. The problem with these PDFs is that they are too BIG!
Let me restate my problem:
I need help writing a script that can “Save” PDFs using the “[Smallest File Size]” setting in Illustrator CS2 with documents that are random sizes other than 8.5"x11". I need this help because without access to the “[Smallest File Size]” setting, the resulting PDFs are too large for my purposes.
Here is an example that might clarify the issue:
I have a non-letter sized Illustrator Document that I made a PDF from with my original script that came out to be 7.5 Mb. When I save this same Illustrator Document manually, selecting the “[Smallest File Size]” setting in the PDF dialog box, the resulting PDF is 1 Mb.
See the difference? Maybe you can use my original script to create a non-letter sized PDF. Then open the same Illustrator file and save it manually as a PDF with the “[Smallest File Size]” setting. Do you see a difference in files size?
(NOTE: To see this point clearly, you should use a rather large Illustrator file.)
I would love to be able to write this “[Smallest File Size]” setting into my script. Does anyone know if this is possible? If not, maybe you can point me to some detailed use of GUI scripting. That me be my only hope.
Thanks to each of you for your time. I hope I don’t sound too harsh in this post.
Simpeton, my apologies I miss understood what you needed
Here is what you are looking for
tell application "Adobe Illustrator"
tell document 1
save in ("" & ((path to current user folder) & ":Desktop:test.pdf")) as pdf with options {PDF preset:"[Smallest File Size]"}
end tell
end tell
See this script I posted you should be able to take what you require from it. Basically all you need do is use the preset in PDF options. You may have missed this it was posted on hi-jacked ID topic. Hope it helps.
mcgrailm YOU ROCK!
Thank you so much for not taking offense at the comments from my last post and then pointing me in the right direction!
Your solution was very simple coding that for some reason I couldn’t put together on my own. No matter though, what you’be given me really works well. The resulting PDF files are now at a manageable size! Your help was excellent.
I gather your problem is solved, However if you don’t want to go down the
preset route. presets are good but not that flexible…
Try this:
tell application "Illustrator CS"
activate
set theDest to (path to desktop folder) as string
set docname to name of document 1 & ".pdf"
set Finalpath to theDest & docname as string
save current document in Finalpath as pdf ¬
with options {class:PDF save options ¬
, compatibility:Acrobat 6 ¬
, acrobat layers:true ¬
, preserve editability:false ¬
, color compression:automatic JPEG low ¬
, compress art:true ¬
, optimization:true ¬
, page info:true ¬
, trim marks:true}
close current document saving no
end tell
it’s the color compression property that reduces the filesize down here. check out the dictionary for other settings than “jpeg low”
The only problem i can see here is with illustrator cs not liking long file names but if you have CS2 then that isn’t problem
Pidge1,
Thanks very much for the details. I figured there would be a way to reduce file size within the individual settings but I must not have dealt with the “jpeg low” setting. Great tip! This will allow me to be more flexible with my final script.
I do have one more question…
First, here is the current working version of the script for creating small PDFs from Adobe Illustrator files. (On my system this requires both Illustrator CS2 and Acrobat 7.0 Professional.)
on open {input_folder}
set openDay to short date string of (current date)
set openTime to time of (current date)
tell application "Finder"
try -- This creates the new folder.
make new folder with properties {name:"Print_n_Save"} at desktop
end try
copy the result to NEWfolder
move contents of input_folder to NEWfolder
--This moves the droped files to the newly created folder.
try
set desktopPDFs to (every file of desktop whose kind is "Adobe PDF document") as alias list
on error -- happens if there is only one
set desktopPDFs to (every file of desktop whose kind is "Adobe PDF document") as alias as list
end try
set PDF_count to the count of desktopPDFs --This variable is the number of PDFs already on the desktop.
try
set input_files to (every file of entire contents of input_folder whose kind is "Adobe Illustrator Document") as alias list
on error -- happens if there is only one
set input_files to (every item of entire contents of input_folder whose kind is "Adobe Illustrator Document") as alias as list
end try
set newPDF_count to the count of input_files --This variable is the number of new PDFs that are about to be printed.
set theDesktop to desktop as string
tell application "Adobe Illustrator" --This section"prints" every Illustrator file.
activate
set printToAcrobat to {class:print options, printer name:"Adobe PDF 7.0"}
repeat with currentFile in input_files
open currentFile
set x to width of current document
set y to height of current document
set thewidth to x div 2.834645 as integer
set theheight to y div 2.834645 as integer
if thewidth is in {215, 279} and theheight is in {215, 279} then
try
print current document options printToAcrobat
end try
else
set theName to name of current document as string
tell document 1
save in ("" & (theDesktop & theName)) as pdf with options {PDF preset:"[Smallest File Size]"}
end tell
end if
close current document saving no
end repeat
end tell
set wait to true --This section delays the script until the PDFs are all "printed" or created.
repeat while wait is true
tell application "Finder"
try
set latestDesktop to (every file of desktop whose kind is "Adobe PDF document") as alias list
on error -- happens if there is only one
set latestDesktop to (every file of desktop whose kind is "Adobe PDF document") as alias as list
end try
set latestPDF_count to the count of latestDesktop
if latestPDF_count is less than (newPDF_count + PDF_count) then
delay 2
else
set wait to false
end if
end tell
end repeat
try --This section finds the "printed" PDFs at the desktop, removes the ".ai" and moves the files to the new folder.
set allPDFs to (every item of desktop whose kind is "Adobe PDF document") as alias list
on error
set allPDFs to (every item of desktop whose kind is "Adobe PDF document") as alias as list
end try
repeat with aPDF in allPDFs
set createdate to creation date of aPDF
set createday to short date string of createdate
set createTime to time of createdate
if createday = openDay and createTime is greater than openTime then
set theName to name of aPDF
set TID to " "
set AppleScript's text item delimiters to ".ai"
set newParts to (text items of theName)
set AppleScript's text item delimiters to ""
set name of aPDF to newParts as string
set AppleScript's text item delimiters to TID
move aPDF to NEWfolder
end if
end repeat
end tell
end open
The lingering issue:
Currently, this script can takes one folder that has been dropped on it. Then it processes the items the folder contains. Problem is, if I drop multiple folders on it at the same time it only processes the items in one of them.
Is it possible to re-write the opening line,
on open {input folder}
so that I can drop multiple folders on it simultaniously? It should then proceed to process all the items inside each of those folders.
Well, nevermind! I began playing with it and I got it to take multiple dropped folders.
Now, to make it work when it is double-clicked with the “on run” command… Any suggestions to help me get there would help also.
on open input_folder
tell application "Finder"
set openDay to short date string of (current date)
set openTime to time of (current date)
try -- This creates the new folder.
make new folder with properties {name:"Print_n_Save"} at desktop
end try
copy the result to NEWfolder
repeat with this_item in input_folder
move this_item to NEWfolder
end repeat
--move contents of input_folder to NEWfolder
--This moves the droped files to the newly created folder.
try
set desktopPDFs to (every file of desktop whose kind is "Adobe PDF document") as alias list
on error -- happens if there is only one
set desktopPDFs to (every file of desktop whose kind is "Adobe PDF document") as alias as list
end try
set PDF_count to the count of desktopPDFs --This variable is the number of PDFs already on the desktop.
try
set input_files to (every file of entire contents of NEWfolder whose kind is "Adobe Illustrator Document") as alias list
on error -- happens if there is only one
set input_files to (every item of entire contents of NEWfolder whose kind is "Adobe Illustrator Document") as alias as list
end try
set newPDF_count to the count of input_files --This variable is the number of new PDFs that are about to be printed.
set theDesktop to desktop as string
tell application "Adobe Illustrator" --This section"prints" every Illustrator file.
activate
set printToAcrobat to {class:print options, printer name:"Adobe PDF 7.0"}
repeat with currentFile in input_files
open currentFile
set x to width of current document
set y to height of current document
set thewidth to x div 2.834645 as integer
set theheight to y div 2.834645 as integer
if thewidth is in {215, 279} and theheight is in {215, 279} then
try
print current document options printToAcrobat
end try
else
set theName to name of current document as string
tell document 1
save in ("" & (theDesktop & theName)) as pdf with options {PDF preset:"[Smallest File Size]"}
end tell
end if
close current document saving no
end repeat
end tell
set wait to true --This section delays the script until the PDFs are all "printed" or created.
repeat while wait is true
tell application "Finder"
try
set latestDesktop to (every file of desktop whose kind is "Adobe PDF document") as alias list
on error -- happens if there is only one
set latestDesktop to (every file of desktop whose kind is "Adobe PDF document") as alias as list
end try
set latestPDF_count to the count of latestDesktop
if latestPDF_count is less than (newPDF_count + PDF_count) then
delay 2
else
set wait to false
end if
end tell
end repeat
try --This section finds the "printed" PDFs at the desktop, removes the ".ai" and moves the files to the new folder.
set allPDFs to (every item of desktop whose kind is "Adobe PDF document") as alias list
on error
set allPDFs to (every item of desktop whose kind is "Adobe PDF document") as alias as list
end try
repeat with aPDF in allPDFs
set createdate to creation date of aPDF
set createday to short date string of createdate
set createTime to time of createdate
if createday = openDay and createTime is greater than openTime then
set theName to name of aPDF
set TID to " "
set AppleScript's text item delimiters to ".ai"
set newParts to (text items of theName)
set AppleScript's text item delimiters to ""
set name of aPDF to newParts as string
set AppleScript's text item delimiters to TID
move aPDF to NEWfolder
end if
end repeat
end tell
end open