Batch convert word documents to pdf (Windows Version)
So I needed to convert 90 word documents to pdf today and the thought of opening up 90 documents and printing them really was really depressing so I made a small vbscript to do it. I was also frustrated by the fact I could not find a ready to use script by searching in google so I made one.
Even though I have Word 2004 and Acrobat Professional 6.0, I couldn't see a way to convert all of them to pdf without opening them individually.
So here is the script (in Word go to Tools->Macros->Visual Basic Editor) click "normal" on the left side tree and click Microsoft Word Object and then double click This Document
Paste in this code:
Sub main()
'** Change the my path variable to the path to your folder full of word docs
myPath = "U:\LAW\syllabi_SP05\docs-toprocess"
Set fso = CreateObject("Scripting.FileSystemObject")
Set Files = fso.GetFolder(myPath).Files
Set app = New Word.Application
For Each file In Files
app.Visible = True
app.Documents.Open (file.Path)
app.ActiveDocument.PrintOut
app.ActiveDocument.Close
Next
app.Quit
Set app = Nothing
End Sub
Be sure to change the path as noted above.
Now the trick is to have a PDF Printer set up as your default printer to print (save) the files to the folder you want. So I hade to make a new printer and create a new port (Adobe PDF port)
set t save to the folder I wanted the files to go to.
Works great 90 word docs were converted in about 3 minutes (unfortunately it took me 2 hours to make the script - oh well next time I will save a lot of time).
You should be able to substitue ghostcript for Adobe Acrobat with a little tinkering.
I also tried to make a unix shell script to do this using a program called Antiword and ghostscript. It worked pretty well. I'll post that later if I can find it
0 Comments:
Post a Comment
<< Home