Script to convert Word and Excel Documents to Jpeg images?

Hello fellow Mac users, I do alot of converting at home…and well…I have a routine of having a word or excel document and then print to pdf then I have to save it as jpeg. (note: I have to start in word and excel and come out with jpeg outputs.) Iv’e been browsing and researching about applescripts and scripting…but I’m just not a scripting wizard yet.

Is there a script that can do the task that I do without having to go through the trouble of creating a pdf. So that it would be possible to have my word or excel document open and simply print to ‘jpeg’.

Any help would be great. Thank you so much.

system info:

Model: PowerPC G5
AppleScript: AppleScript 1.10.6
Browser: Safari 417.9.3
Operating System: Mac OS X (10.4)

This would be a simple task using both Word and Image Events, except that the [print to PDF] is unavailable or simply dysfuntional when scripting Word. According to the Microsoft Word Reference, this code should work:

set a to (path to desktop as Unicode text) & "WordPrint"
tell application "Microsoft Word"
	print out active document output file name a with print to file
end tell

However, it only generates a "Doesn’t understand the print out message’ error. There is a short thread here on using GUI scripting to make Word print to a PDF, but it is also dysfunctional, probably due to a change in the UI elements for making it happen. I am not familiar enough with GUI scripting to take a stab at it.

Once you have the PDF, it is a simple thing to convert to JPG:

set main_path to (path to desktop as Unicode text) & "PDF2jpg.jpg"
set selectedFile to (choose file)
tell application "Image Events"
	set openedFile to open (selectedFile as alias)
	save openedFile in main_path as JPEG
end tell

There are plenty of GUI scripters here, perhaps someone can figure out the Word angle, and you can go from there. If there is no response to this thread, start another one with the specific information in the subject about GUI scripting in Word to generate a PDF file.

Good luck,

Thanks Craig!

Im a real beginner with these things…I do have a strong interest to learn scripting. I have a novice question though…

The script you posted…where should I copy it to? I’m assuming I should open the applescript application and make a new script…if so…where do I then save it? so that it will function the way its supposed to?

Im full of questions…but I am really hungry to learn. I was a windows PC user till I bumped into the MAC…(which I like alot).

Any help would mean so much to me! Thank you again.

Start at the beginning, of course! For scripting, the real beginning is Script Editor, the application you would use to start writing scripts for different applications. As it happens, the ScriptWire article for this week is my contribution to the beginning AppleScripter. To open up any script on MacScripter that is inside the nifty boxes that state ‘Open this Scriplet in your Editor,’ simply click on that statment, and voila! You have an un-compiled script ready in your Editor. I recommend that you read through the article, set your system up, and then the next great places to start are here:
a free download book that covers the basics of Applescript. We have a nice books page with some various texts if you want some good reading. This book and this one are my two favorites for ultra beginner information. We also have a Links page that may have sources to help you get your keyboard wet.

As luck would have it, Microsoft Word is one of the more challenging applications to script, so you will probably get pretty frustrated until you stumble across the right syntax, or someone else jumps in with the solution.

Brilliant Craig! I learned plenty already just by reading your intro article. Amazing. I’m definitely officially hooked.

Is there a way that I could subsrcibe to your articles? So that I can continue along…and learn from you.

You’ve done wonders already!

You are very kind, thank you. The ScriptWire articles run for a week, starting every Monday. I think I am scheduled for one every month, so it will take awhile for me to get a bunch of Beginning chapters. The idea at ScriptWire is to offer something for everyone on a regular basis, so they rotate through Beginning, Intermediate, Advanced, and whatever else Adam Bell wants to put up there.

AppleScript is addicting, so enjoy the ride!

Craig has given a very nice summary of our intentions with ScriptWire - the series of articles on the cover page of MacScripter.net. For as long as he is willing, we’ll have a Beginner’s article by Craig like the one on the cover now on a once/month basis, and these will all be archived in the “unScripted” section of MacScripter. At the beginning of every month, we’ll run a Beginner/Intermediate article by Ben Waldie along the lines of his recent “Getting Started with Handlers (Part 1)”, now archived. Between Craig’s and Ben’s regular appearances, we’ll feature more specialized articles like Diana Simonson’s “Automating Mugshots into Filemaker from iSight using Applescript”, Intermediate articles like my own “Using AppleScript’s Text Item Delimiters for Text Manipulations”, and more Advanced articles explaining the nuances of AppleScript like Nigel Garvey’s “Range References with AppleScript Text and Lists”.

I hope they all reach an audience as responsive as keleric has been above, so as Craig says, enjoy the ride, and don’t hesitate to write for coverage of something that bugs you.

Adam Bell