Sunday, September 20, 2009

OSX - bulk convert to PDF

OSX has a convert utility that you can use to bulk convert documents in PDF. IN essence if the OS support viewing and printing them, you can convert them.

To convert a single file you can use

/System/Library/Printers/Libraries/convert -f path/to/source.file -o destination.pdf

If you want to convert in bulk you can use AppleScript.

Open Script Editor from /Applications/AppleScript, then in a new script copy and paste

on open input_documents
repeat with this_document in input_documents
set this_document_path to POSIX path of this_document
--display dialog this_document_path
do shell script "/System/Library/Printers/Libraries/convert -f " & quoted form of this_document_path & " -o " & quoted form of this_document_path & ".pdf"
end repeat
end open

then from File Menu select Save As. In File Format select Application. Give it a name, and then you can drag and drop your files onto it, and hey presto converted to PDF.


RaelIAK said...

get an error message concerning the MIME type of the file I tried to convert to pdf using your script...

Unknown said...

What kind of file did you try?

RaelIAK said...

A FreeHand one. Actually, the only kind of file sthat gives me trouble getting a pdf from, in Snow Leopard.

Unknown said...

So this is most likely a problem with your file, not with my script?

Is the file damaged? Can you copy elements to a new file?

RaelIAK said...

I get the same error message for every FH file I tried to print to pdf using your script.
Unfortunately, FH's files are the only one giving me problems when trying to get a pdf from the print panel (I first have to generate a .ps then get it converted to pdf with Distiller). It's a long way to get a "stupid" pdf. Thought your script would have eased my pain.
But it didn't...

Unknown said...

My guess would be that OSX has no built-in converters / viewers for Freehand files. I only have Freehand MX (ie v11) and get the same error on both v11 and v10 files.

If I export from FH as png that converts no problem using the script, so my guess is that the CUPS converter doesn't like Freehand files.

Maybe you could make an AppleScript that open each file and exports to PDF?

Unknown said...

I tried this with a .doc file but I got the error convert: "Unable to determine MIME type of "document.doc"!

Does that mean OS X doesn't have built in convertors for .doc files?

Anonymous said...

That would be my guess. If you are using 10.5 / Leopard or 10.6 / Snow Leopard, and you select the file and press the space bar for the Quick Look (if I hav that correct) what do you see?