PDF2JEPG

HI folks,
i’m a complete newbie to scripting so any and all help is appreciated. I want to convert PDF documents to JEPG. I can achieve this in Graphic converter but I would like to create a folder action or other script to do the job through GC or not.

many thanks

If you’re using OS 10.3, the built-in Image Events scripting component can do the job for you, no additional software required.

This is a subroutine I use in production for daily PDF-to-JPG converts. Although it does a bit more than you might need, it should contain all you need to get started with Image Events.

on processFiles(someRootFolder, someInFolder, someOutfolder, someThumbFolder, someArchiveFolder, someErrorFolder)
	tell application "Finder"
		set newFiles to every file in someInFolder whose name ends with ".pdf" or name ends with ".PDF"
	end tell
	tell application "Image Events" to launch
	repeat with f in newFiles
		tell application "Finder"
			set fName to name of f
			set shortName to (text 1 through -5 of fName)
			try
				delete file (shortName & ".jpg") of someOutfolder
				delete file (shortName & ".jpg") of someThumbFolder
				delete file (shortName & ".pdf") of someArchiveFolder
				delete file (shortName & ".pdf") of someErrorFolder
			end try
			set iProps to info for file (f as string)
			set iBusy to busy status of iProps
		end tell
		if iBusy ? true then
			try
				tell application "Image Events"
					set this_PDF to open (f as string)
					set myProps to properties of this_PDF
					set {myWidth, myHght} to {(item 1 of (dimensions of myProps)), (item 2 of (dimensions of myProps))}
					if myWidth > 770 then
						set myPerc to (770 / myWidth)
						scale this_PDF by factor myPerc
						save this_PDF as JPEG in (someOutfolder as string) with icon
						save this_PDF as JPEG in ((folder "JPG_ARCHIVE" of someRootFolder) as string) with icon
					else
						save this_PDF as JPEG in (someOutfolder as string) with icon
						save this_PDF as JPEG in ((folder "JPG_ARCHIVE" of someRootFolder) as string) with icon
					end if
					scale this_PDF to size 120
					save this_PDF as JPEG in (someThumbFolder as string) with icon
					close this_PDF saving no
				end tell
				tell application "Finder"
					move f to someArchiveFolder
				end tell
			on error
				tell application "Finder"
					move f to someErrorFolder with replacing
				end tell
			end try
		end if
	end repeat
end processFiles

Hi T.J.,
thanks for that, however the script gives me an error in the section below

set iProps to info for file (f as string)
set iBusy to busy status of iProps
end tell
if iBusy ? true then
try
tell application “Image Events”

If I change the ? (line 4 above) to is the error is gone but I can’t seem to get the script to do anything

thanks again

That ‘?’ seems to have sneaked in there via some copy/paste translation thing.

Change ‘?’ to ? (is not equal to)

I’m afraid still no joy, nothing happens

Cheers

Well, it has worked flawlessly for me, unattended for months.
I suspect it’s just not getting all the proper or valid parameters passed to it. Remember, this is a subroutine and isn’t intented to work all by itself; you must insert it into your script and call it properly.

I’d recommend you strip out all but the most basic functionality you need.
Good luck.

Try this attached as a folder action:


on adding folder items to this_folder after receiving these_items
	delay 1
	set thisFIle to first item of these_items as alias
	my ConvertPDF2JPEG(thisFIle)
end adding folder items to

to ConvertPDF2JPEG(thisFIle)
	tell application "Finder"
		set theFolder to (container of thisFIle as alias)
		set thisInfo to info for thisFIle
		set thisName to the name of thisInfo
		set thisExt to name extension of thisInfo
		set newName to text 1 thru -((length of thisExt) + 2) of thisName
		set newFullName to newName & "." & "jpg"
		tell application "Image Events"
			launch
			set x to open thisFIle
			save x as JPEG in file newFullName of theFolder
			close x
		end tell
		delete thisFIle
	end tell
	return
end ConvertPDF2JPEG

I have been using this as my pdf2jpg folder action attached to the desktop for instant screenshot conversion


on adding folder items to this_folder after receiving these_items
	repeat with each_item in these_items
		if kind of (info for each_item) is "PDF Document" and name of (info for each_item) starts with "Picture" then
			display dialog "What shall we call the image?" default answer "screenshot" buttons {"Ok"} default button 1
			set outputName to text returned of result
			tell application "Image Events"
				open each_item
				set picData to its first image
				save picData as JPEG in ((this_folder as string) & outputName & ".jpg")
			end tell
                            --- MUFFLE
		end if
	end repeat
end adding folder items to

hello,

none of this scripts work for me if i add more than one pdf file?
is there a solution?

greets