Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch convert Mac iWork files to PDF on the command line

I'm trying to batch convert a bunch of assorted iWork files (Numbers, Pages, Keynote) to PDF on the command line.

I've been trying cups-filter but there's no MIME type filter for the iWork types. I then looked into using qlmanage to generate the preview image and use that, but this doesn't seem to work for multi file Keynote documents as they generate as HTML rather than PDF.

Any suggestions? I'd rather not resort to AppleScript.

like image 477
NeilInglis Avatar asked Dec 28 '22 03:12

NeilInglis


2 Answers

Here's what I ended up going with, since I really wanted to avoid, AppleScript.

When saving an iWork document there's a "Include Preview In Document" checkbox. Checking this creates a "QuickLook/Preview.pdf" inside the iWork document bundle (which is actually a zip file). Luckily I had this checked for most of the zip files, so it was simply a case of unzipping to NSTemporaryDirectory and grabbing that file.

For those that didn't I put together a script to run qlmanage to create the document preview. For some that creates the PDF, for others it creates an HTML file. You can then use http://code.google.com/p/wkhtmltopdf/ to convert this HTML to a PDF.

like image 125
NeilInglis Avatar answered Dec 30 '22 11:12

NeilInglis


I created an .applescript script that converts all .pages files within a folder to .docx. .pdf support can be easily added. In pages2docx.applescript you just need to replace Microsoft Word with PDF.

like image 41
bamboofighter Avatar answered Dec 30 '22 12:12

bamboofighter