PDF to JPG using Image Events?

I’m trying to write a script that will take a PDF and scale it down to 2 different sizes and save out 2 versions of it, a thumbnail and a slightly larger image.

I’m trying to figure out how to handle a multipage PDF. This script seems to work fine with the first page of the PDF only.

Any help would greatly be appreciated.

Thanks
Brian


on adding folder items to this_folder after receiving these_items
	repeat with this_item in these_items
		tell application "Finder" to set file_name to name of (this_item as alias)
		
		set name_length to count of items in file_name
		if (name_length > 24) then set name_length to 24
		
		set dest_name to (this_folder as Unicode text) & (items 1 thru (name_length - 4) in file_name & ".jpg") as text
		set thumb_name to (this_folder as Unicode text) & (items 1 thru (name_length - 4) in file_name & "_thumb.jpg") as text
		
		tell application "Image Events"
			launch
			
			set large_jpg to open (this_item as alias)
			
			copy (dimensions of large_jpg) to {W, H}
			
			if (W > H) then
				scale large_jpg to size 600
			else
				scale large_jpg to size 415
			end if
			
			save large_jpg as JPEG in dest_name with icon
			
			close large_jpg
		end tell
		
		tell application "Image Events"
			launch
			
			set thumbnail to open (this_item as alias)
			
			copy (dimensions of large_jpg) to {W, H}
			
			if (W > H) then
				scale thumbnail to size 130
			else
				scale thumbnail to size 90
			end if
			
			save thumbnail as JPEG in thumb_name with icon
			
			close thumbnail
		end tell
		
	end repeat
end adding folder items to

Hi Brian,

you’ll need a tool to split the multipage-pdf, then run your script. image events can’t do the job.

a simple and easy to use commandline tool is joinPDF: http://download.cnet.com/1770-20_4-0.html?query=joinpdf&tag=srch&searchtype=downloads&filterName=platform%3DMac%2CWebware&filter=platform%3DMac%2CWebware

the splitcommand usage:

set PdfFile to quoted form of POSIX path of ((choose file) as text) 
do shell script "splitPDF " & PdfFile 

Hans