Quickly creating PDFs from a group of Illustrator files

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

Hi Simpleton

There has been a few posts on the forum regarding printing from illustrator.
the end result been at the default size which is as you say 8.5"x11" anything bigger than this gets cropped to this size.
if you are just after a bog standard illustrator pdf you can script this directly you don’t have to go thru the postscript printing option. (i.e. AdobePDF 7.0)
This way you won’t get the size issue.
There was an issue in CS1 regarding long filenames truncating but this has been resolved in CS2

I do have a script for this but not on this machine if your interested, its on a work machine!
I think it depends on what you will be using the resulting pdf for, i’ve heard that people prefer the pdf that comes from a postscript file
rather from illustrator’s save as command.
Although i only use them mainly for visual purposes so there fine for me.

cheers

pidge1,
Thanks for the reply. I understand what you are saying about not “printing” to PDF but I really like how small the resulting files are when you print to “Adobe PDF 7.0”. Maybe I’ll have to “save as” any PDF that is any other size besides 8.5"x11" but I am still interested in finding a way to get the document size once Illustrator opens the file. Never the less, I would be interested in your script. Thanks.

All,
Does anyone know how to get the current document size when scripting Adobe Illustrator CS2? If someone could help me with that, I could set up the script to test for the size and then create the PDF accordingly. Any thoughts? Thanks.

Hi simpleton

Haven’t had chance to dig out the pdf script yet.(very busy!)
try this to get size of current open document in illustrator.

tell application "Adobe Illustrator"
	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
	display dialog "The Document size is" & space & thewidth & "x" & theheight & "mm"
end tell
--> size in millimetres

Hey Simpleton

pdf script

on open |illustrator files|
	repeat with |the files| in the |illustrator files|
		tell application "Adobe Illustrator"
			activate
			open |the files|
			set docname to name of document 1
			tell application "Finder" to set Finalpath to (path to desktop folder) & docname & ".pdf" 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}
			--, PDF preset:"Hi-Res pdf"}
			close current document saving no
		end tell
	end repeat
end open

its set has a droplet.
you might want to add the bit of code from yours which removes the “.ai” bit out so you don’t get “.ai.pdf”