www.nickhodge.com

microsoft, munging and on being a mercurial iconoclastic professional geek.

Moonshine: Distilling PDF into JPEG using Scripting

without comments

Dis­tilling PDF into JPEG Pho­toshop 7.0’s scripting

Prob­lem from a cus­tomer: they cre­ate many, many PDFs for both cli­ent sign off and deliv­ery as final form doc­u­ments. How­ever, they need a mech­an­ism of per­mit­ting their cli­ents to “pre­view” the PDFs online before down­load­ing for signoff.

So, out with the new­est Adobe applic­a­tion on the block: Pho­toshop 7.0. Pho­toshop 7.0 has a major new addi­tion: Script­ab­il­ity. Using AppleScript on MacOS, VB (COM) script­ing on Win­dows and Javas­cript on both plat­forms, you can write scripts that inter­act with Pho­toshop and other applic­a­tions. For scripters, this is the holy grail. From my first days at Adobe, one of the gurus of Apple­Script­ing Shane Stan­ley, houn­ded me about Pho­toshop script­ab­il­ity. In Pho­toshop 7.0, we’ve finally delivered.

This script is quite simple: once launched, it watches one dir­ect­ory for PDFs. Once one arrives, it askes Pho­toshop to open and ras­ter­ise it. After con­vert­ing it to RGB, it res­izes to a par­tic­u­lar width, then saves a JPEG into an out dir­ect­ory. The PDF is moved to a done dir­ect­ory. They are not deleted.

The first thing you need to do with the file moon­shine source script is cus­tom­ise the paths the script “looks at” in its pro­cessing. The tar­get image width also needs to be set.

[1125] four lines to customise

After edit­ing these four prop­er­ties, you will need to save the script as an applic­a­tion and to stay open. This script has an “idle” hand­ler: essen­tially it peri­od­ic­ally checks that in dir­ect­ory for new PDFs to work on.

[1123] Save As Application Stay Open

You will need the AppleScript plu­gin for Pho­toshop 7.0: Pho­toshop 7.0 Script­ing Plu­gin 1.0.2a (Mac)

And my script which is here:
MacOS X 10.2.6:  Moon­shine for MacOS X 10.2.6
 MacOS X: Moon­shine for MacOS X

 MacOS 9: Moon­shine for MacOS9

Why as spe­cific MacOS X script? This script uses the Finder’s file extension prop­erty of a file to determ­ine if a par­tic­u­lar file is a PDF. This doesn’t seem to be imple­men­ted in MacOS 9.2.2’s Finder script­ing dic­tion­ary. This is easy to replace with a string com­par­ison of the file name. Why a MacOS X 10.2.6 Script? Apple, in their infin­ite wis­dom, slightly changed the script­ing dic­tion­ary in the Finder at some stage and this has res­ul­ted in a minor script change. Thanks Wil­liam for the heads-up.

Written by Nick Hodge

June 16th, 2003 at 10:00 am

Posted in mungenet