Have you ever wanted to directly create dynamic PDF documents from within your AppleScripts? In less than a second? While having full control over page dimensions, color space and the exact positions of inserted texts, graphics and images? Well, if your answer is a resounding Yes, then I kindly invite you to download and inspect my latest Mac scripting project:
Colendar is an AppleScript Studio application that requires Mac OS X 10.5 Leopard and the system font Andale Mono. Just like my RagTime template it can create customized PDF calendars in several languages, but - and that is important - without the need of owning a copy of RagTime. It just creates the whole PDF document completely on its own.
Now, how can our beloved language of automation instantly create rich PDF content without installing extensions like Smile? Frankly spoken, it cannot. The real magic of direct PDF calendar creation is not achieved by AppleScript itself. It’s done by a Python script that makes excessive use of the excellent Quartz 2D bindings for Python. And that is also why you necessarily need Mac OS X 10.5 to successfully run Colendar, because the Python script relies on the latest version of PyObjC, which is pre-installed on Leopard.
But don’t underestimate the power of this combination! By having the possibility to execute Python scripts with arguments from within your AppleScript code using the «do shell script command», you can easily create a Python script that creates a nicely formatted and layouted PDF document with data retrieved from the calling AppleScript.
For example, one could quickly extend Colendar to include birthdays from an iCal calendar. Or think about an AppleScript based Apple Mail rule, that extracts all available informations from an incoming eMail and then calls a Python script, which produces a corresponding PDF representation of that message to file or directly print it with the lpr command. A thousand possibilities!
You only need to keep in mind, that currently all characters used in text to be drawn to a PDF context must be able to be converted to Mac Roman text encoding. Therefor not all languages can be supported. And just in case I watered your mouth and you want to dive into Python and direct PDF creation, I recommend to install the Developer Tools and take a look at the code examples located in /Developer/Examples/Quartz/Python/ and /Developer/Examples/Python/PyObjC/. Of course, studying the well commented Python script which is responsible for the PDF calendars produced with Colendar might also be a good idea
Let’s build a great web service!
I would really like to put the underlying Python script on a server running Mac OS X Server (10.5), so that anybody could create and download colorful PDF calendars online. But unfortunately I don’t have access to such a server and don’t want to offer such a service out of my living room using my limited bandwidth, DynDNS and an old but still beautiful Power Mac G4/400…
So if you have access to a server running Mac OS X Server 10.5 and are interested in creating such a calendar creation service, please do not hesitate to contact me!