I’ve been working on a script for some time to help get files out to print.
One of the key parts of this is having the script create PDFs directly from the Illustrator files. This is actually pretty simple with CS2 because I have the option to “print” to “Adobe PDF 7.0” instead of a physical printer. I’m sure some of you are familiar with this process but for those that aren’t, AI CS2 interestingly/annoyingly does not allow you to choose where the resulting PDF file is created or what it will be called; it just spits out the new PDF onto your desktop and adds “.pdf” to the end of the file name.
This script is a droplet that takes any/all Illustrator files dropped on it, opens them in Illustrator and “prints” them to the desktop as a PDF. Meanwhile, the script creates a new folder that the dropped AI files go into. Once all the new PDFs are created at the desktop, the script moves them to the new folder and removes the “.ai” so each file name is now “filename.pdf” instead of “filename.ai.pdf”.
I’m really pleased with how well this works except for one thing…
All resulting PDFs are 8.5"x11", regardless of the original Illustrator file dimensions. Can someone help me figure a way to retrieve the document size of the AI files and then make that part of the specifications for the new PDF?
Here’s the script so far:
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:"test folder"} 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.
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
try
print current document options printToAcrobat
on error
select every item in current document
end try
close current document saving no
end repeat
end tell
set wait to true --This section delays the script until the PDFs are all "printed".
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 upload 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