Converting a PDF to a series of images.

Today I needed to convert a PDF file to a series of images. Initially I was a little stumped on how to do this easily on my Mac.

My first port of call was Preview. Preview is one of Mac OS X’s most useful tools, but for this task it let me down.

You can use Preview to save a PDF file to a variety of other image formats just by choosing “Save As…” from the File menu. Preview will then ask you to specify a format and other image options. Unfortunately when you choose to save in the PNG image file format, this saves just the current page you are viewing. What I wanted was each page of the entire PDF to be saved to a separate file.

My next thought was perhaps I could use AppleScript to automate Preview. Unfortunately Preview is one of the few Apple tools that doesn’t support AppleScript very well (if at all).

Render PDF Pages as Images Automator workflow

This lead me to think about Apple’s Automator tool, and I discovered that Automator has an action called “Render PDF Pages as Images”. Hurrah! Problem solved! Well, not quite. I’m not an Automator expert so I had a little trouble figuring out how to use it. In the end I constructed the following workflow.

  1. Render PDF Pages as Images
  2. Rename Finder Items (set to Make Sequential mode)
  3. Move Finder Items
  4. Reveal Finder Items

When I was creating this workflow I was concerned about there not being any way to specify which folder to save the images into and other options on each workflow step.  However I then discovered the “Show this action when the workflow runs” check box in the options section of each action.  When this checkbox is enabled the action will pop up a dialog and ask the user to specify certain options.  In the case of the Render Pages as Images action you can specify the image format and DPI settings.  For the Move Finder Items action you can specify the destination directory.

I saved this workflow as an “Application” and now I have an icon I can drag a PDF onto to create a series of images.

Apple’s mod_bonjour is broken in Snow Leopard, so I fixed it.

I was playing about with Apache on my iMac and I noticed a little file tucked away in /etc/apache2/other called bonjour.conf.  Intrigued I set about figuring out what it was for.

This file had some directives relating to an Apache module called mod_bonjour.  The purpose of which is to register URLs with Apple’s Boujour service.  This service lets systems and services publish their existence on a local area network so other systems and applications can find them without configuration.  Boujour is just Apple’s marketing speak for Zeroconf style networking.  It is also known as multicast DNS and is common on Linux and Apple systems.

Safari on MacOS even has a Bonjour menu that displays services or devices that are advertising themselves via the Bonjour service.  An example of this is my QNAP NAS.  I can always easily access the Admin interface of my NAS (and other services the NAS provides) because it advertises itself with Bonjour.

I thought that using Bonjour would be rather handy for advertising some web applications I had configured on my iMac to other systems on my home network.  So I added them to the bonjour.conf configuration file like so:

RegisterUserSite customized-users
RegisterResource “Confluence” “/confluence”
RegisterResource “TeamCity” “/teamcity”

Unfortunately after restarting Apache I was dismayed to discover that only the last RegisterResource directive seemed to be working (TeamCity), as it was the only resource showing up in the Bonjour menu in Safari.

However after a quick search for mod_bonjour with Google I discovered two posts detailing the problem.  There is a bug in mod_bonjour.

Joe Maller found the bug and supposedly reported it to Apple in 2007, and Chuck Houpt even created and released a patch for the Leopard release of Mac OS X.

Now I’m running Snow Leopard so I didn’t want to just use the patched binary Chuck provided, so I set about patching the Snow Leopard version of this module.  Fortunately Apple provide the source code to this module on their open source site.  So I took what appears to be the code from Snow Leopard, applied Chuck’s patch and produced a version for Snow Leopard.

In order to share this updated code with the wider Internet I’ve created a GitHub code repository for it.  In order to build this code and update your Mac you will need the Apple Developer Tools installed.

Is Iron Man made of Lego?

I was re-watching Iron Man recently and noticed something interesting.  During Iron Man’s first “boot up sequence”, in the “terrorist” caves of Nowhereistan, some butchered C code is displayed on a faked up laptop screen.

C source code from Iron Man Movie

The code displayed on screen, although missing some syntactically important characters such as semi-colons, is actual valid C source code.  So valid in fact that I wondered where it came from.

After a quick Google I found it. This code is in fact as follows:

    send[0] = 0x65;
    send[1] = 1;
    send[2] = 3;
    send[3] = 5;
    send[4] = 7;
    send[5] = 11;

    if (rcx_sendrecv(fd, send, 6, recv, 1, 50, RETRIES, use_comp) != 1) {
	fprintf(stderr, "%s: delete firmware failed\n", progname);

    /* Start firmware download */
    send[0] = 0x75;
    send[1] = (start >> 0) & 0xff;
    send[2] = (start >> 8) & 0xff;
    send[3] = (cksum >> 0) & 0xff;
    send[4] = (cksum >> 8) & 0xff;
    send[5] = 0;

    if (rcx_sendrecv(fd, send, 6, recv, 2, 50, RETRIES, use_comp) != 2) {
	fprintf(stderr, "%s: start firmware download failed\n", progname);

    /* Transfer data */
    addr = 0;
    index = 1;
    for (addr = 0, index = 1; addr < len; addr += size, index++) {

The code above comes from a firmware downloader for the RCX (a programmable, microcontroller-based Lego brick), written in 1998 at Stanford University by Kekoa Proudfoot. You can get the full source file here and it is distributed under the Mozilla Public License.  This is the same license used by Firefox and many other Open Source software products.

The sequence in the film in which this code appears suggests that the code is either being downloaded as firmware to the Iron Man suit or being used to upload firmware to an RCX Lego brick that is somehow involved in the operation of Iron Man.

So it appears that Iron Man is either powered by Open Source software or made of Lego.  I’m not sure which is cooler.

Telestream Screenflow e-Commerce FAIL & Twitter

Screenflow LogoRecently I had a need to create a screencast to help my father learn how to use his new Mac. I’d seen Telestream Screenflow used in the past and from that, and a little play with the trial version, I decided I’d purchase the app for my Mac.

Although Screenflow is a bit expensive at 99USD, it has a lot of cool features, so I was all prepped and waving my credit card around ready to buy. Unfortunately when I went to Telestream’s eSellerate powered store it didn’t even list the application for sale.

Epic sales FAIL.

The chaps at Telestream however had made the smart decision to list their Twitter name on their site (@screenflow). So I tweeted a little note about how their store was broken when I had wanted to buy and that they had lost a sale.

I then went on to use Snapz Pro X, which I already own, to make my little screencast.

The next day, @screenflow tweeted me a little direct message asking for my email address, which I provided. Lo-and-behold, in response they send me a coupon code for a 100% discount for my troubles. Nice.

Thanks Telestream, that’s what I call customer service.

Blast from the past.

While saving a document in Word 2003 the other day, my colleague Phil witnessed Word spit the dummy and display this dialog.

Format what?
Format what?

It appears to be some sort of vestigial error dialog from Word 6.0 for Windows 3.1.  Check out the awesome ASCII art bullet points and encouragement to format another floppy disk.

Sure I’ll just whip out and pop in a 3.5″ floppy and do that right away.

Essential Mac Add-on

I just found an essential MacOS X add-on.

One of the things I find annoying with the Mac is the fact that there are no keyboard shortcuts for window management beyond minimizing and hiding an application’s windows.

My desktop screen is larger in both size and resolution than my MacBook’s built in display.  So when I’m travelling often I’ll open up an application, say iTunes for example, and the window will be larger than my screen can accomodate.  The borders of the window and the resize grab handle will be off screen with no way for me to mouse to the right place and resize the window to fit.

Enter MercuryMover.  This System Preference Pane provides customizable keyboard shortcuts and a nice little overlay GUI for manipulating windows with the keyboard.  Now I don’t mind paying the $20 to buy this app because it is damn useful, but this sort of feature should really be built-in to MacOS X.  Hopefully Apple will do that one day.  I don’t hold out much hope though.

My iPhone 3G hates my Linksys WAG54G V.3

Since getting my lovely new iPhone 3G I’ve only been able to connect to my apartment’s Linksys WAG54G V.3 using 802.11b.  It steadfastly refused to talk in “mixed” or “G-Only” mode when WPA-PSK encryption was turned on.

A little snooping behind the scenes, using the Organizer in Xcode to read the iPhone’s log, revealed that the poor little fella was having a problem with a “timeout waiting for authentication response” when connecting to the wireless LAN.

A little Googling and reading of anguished forum posts lead me to the solution.  I just needed to upgrade the Firmware on the Linksys to v1.00.46.

Now my iPhone can enjoy the benefits of 802.11G.  Success!

Perhaps this firmware upgrade will also fix my ADSL2+ signal strength issue too.  Time to test…