About Me

microformats hcard approaching

is a Professional Geek for Microsoft Australia. More info lives underneath the About Box...

33.831416, 151.222526
MrCell+61.417.212181
Work:
1 Epping Road
North Ryde, NSW 2113
Australia
photo of nick hodge

Blog Flair

Subscribe to me on FriendFeed

feedburner

View Nick Hodge's profile on LinkedIn

msdn channel 9

Moonshine: Distilling PDF into JPEG using Scripting

By Nick Hodge | June 16, 2003

Distilling PDF into JPEG Photoshop 7.0's scripting

Problem from a customer: they create many, many PDFs for both client sign off and delivery as final form documents. However, they need a mechanism of permitting their clients to "preview" the PDFs online before downloading for signoff.

So, out with the newest Adobe application on the block: Photoshop 7.0. Photoshop 7.0 has a major new addition: Scriptability. Using AppleScript on MacOS, VB (COM) scripting on Windows and Javascript on both platforms, you can write scripts that interact with Photoshop and other applications. For scripters, this is the holy grail. From my first days at Adobe, one of the gurus of AppleScripting Shane Stanley, hounded me about Photoshop scriptability. In Photoshop 7.0, we've finally delivered.

This script is quite simple: once launched, it watches one directory for PDFs. Once one arrives, it askes Photoshop to open and rasterise it. After converting it to RGB, it resizes to a particular width, then saves a JPEG into an out directory. The PDF is moved to a done directory. They are not deleted.

The first thing you need to do with the file moonshine source script is customise the paths the script "looks at" in its processing. The target image width also needs to be set.

[1125] four lines to customise

After editing these four properties, you will need to save the script as an application and to stay open. This script has an "idle" handler: essentially it periodically checks that in directory for new PDFs to work on.

[1123] Save As Application Stay Open

You will need the AppleScript plugin for Photoshop 7.0: Photoshop 7.0 Scripting Plugin 1.0.2a (Mac)

And my script which is here:
MacOS X 10.2.6:  Moonshine for MacOS X 10.2.6
 MacOS X: Moonshine for MacOS X

 MacOS 9: Moonshine for MacOS9

Why as specific MacOS X script? This script uses the Finder's file extension property of a file to determine if a particular file is a PDF. This doesn't seem to be implemented in MacOS 9.2.2's Finder scripting dictionary. This is easy to replace with a string comparison of the file name. Why a MacOS X 10.2.6 Script? Apple, in their infinite wisdom, slightly changed the scripting dictionary in the Finder at some stage and this has resulted in a minor script change. Thanks William for the heads-up.

Topics: mungenet |

Comments