Batch convert Word files to PDFs

Mar 16, '07 07:30:04AM

Contributed by: ctopfel

I had a lot of Word documents to convert to PDF files, and I found it annoying that I had to use File » PRint and then pick the Save as PDF option from the pop-up menu for each of the 200 files. So I found a solution: Install the CUPS-PDF module for OS X. This is a virtual PDF printer that looks like a "real" printer to the system, but creates a PDF file when you send a document to it. Make sure to install it correctly in Printer Setup, and (important!) make it your default printer.

Now go into Microsoft Word, and create a new Macro (name: testprintpdfs). Paste in the following code:

Sub testprintpdfs()
'
' testprintpdfs macro
' batch pdf print test
'

For i = 1 To 110
    ActiveDocument.PrintOut
    'Dialogs(wdDialogFilePrint).Show
    ActiveWindow.Close
Next i
End Sub
Now open all your files in Word, and execute the macro. It will send a direct print command (without the dialog) and close the current document. It will continue to do this until there are no open documents left -- it will finally give an error, but I didn't care about that. Your PDF files should now be located on your desktop in the cups-pdf folder. They will have some junk (__MICROSFT_WORD_) in front, which you can remove with a simple shell script, Automator, or your other favored file renaming tool.

I hope this hint can save some of you some time, and I am looking forward to reading comments or suggestions for improvements.

[robg adds: Looking at the code, you should probably adjust the For i = 1 to 110 line to reflect the number of documents you plan on converting. This will stop the error from occurring, but this fix isn't critical. We have an older hint here that talked about another way of creating a CUPS PDF printer, but the above-linked package seems like a very nice solution, and it's the first I've heard of it.]

Comments (14)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20070315023808642