IAC – Automating batch Word DOC conversion to PDF using ‘Acrobat Distiller’ printer

Here is some VB code that will allow you to create PDF documents in batch using Acrobat 4’s
‘Acrobat Distiller’ printer. Your files will be deposited in the Acrobat 4 – PDF Output folder, usually
c:Program FilesAdobeAcrobat 4.0PDF Output

This is a simple demonstration of how all Word files in a given folder can be converted to PDFs. The

Acrobat Distiller printer (installed with Acrobat 4) must be configured and operational for this to work. No

bookmarks or hyperlinks are added – just plain old vanilla PDF. You’ll also notice that the printername is

hardcoded. It would be a good idea to have this set as a variable. Use this as you see fit, however, be aware it hasn’t been tested for scalability or reliability.

Brief Instructions

Create a new VB project, add a button called ‘btnConvert’, an edit control called ‘m_txtSource’, and
paste the following code into the form code section.

To run the program, type name of the folder with your PDFs into the edit control and click the
convert button.

*** Don't forget to reference the Word.8 library in your project
*** You'll want to make sure that Distiller is not setup to prompt
*** you for filenames


Function ConvertFile(strSourceFileName As String) As String
On Error GoTo ErrorHandler

Dim msWord As Word.Application
Set msWord = GetObject(Class:='Word.Application.8')

msWord.Visible = True
msWord.ActivePrinter = 'Acrobat Distiller'
msWord.Documents.Open strSourceFileName
msWord.ActiveDocument.Close False

' Should check and quit word when done
Set msWord = Nothing
ConvertFile = True
Exit Function

' Create Word for the first time if it is not active
If Err.Number = 429 Then
Set msWord = CreateObject('Word.Application.8')
Err.Clear ' Clear Err object in case error occurred.
End If

' All other errors handled here
If IsCriticalError Then
ConvertFile = False
Exit Function
End If
End Function


Private Function IsCriticalError() As Boolean
Dim strErrorMessage As String
Select Case Err.Number ' Evaluate error number.
Case Else
strErrorMessage = 'Please contact

info@planetpdf.com and inform them that' & Chr$(13) & _
'the error message reported by the operating system

was ' & Chr$(13) & _
Chr$(34) + Trim(Str(Err.Number)) & ' ' &

Err.Description + Chr$(34)
MsgBox strErrorMessage, , 'Conversion error' +

IsCriticalError = True
Exit Function
End Select
IsCriticalError = False
End Function


Private Sub btnConvert_Click()
Dim strFileToConvert As String
Dim strFolder As String

' Set the source folder
strFolder = m_txtSource

' Grab the first file to convert
strFileToConvert = Dir(strFolder + '*.doc')

' Loop through all word files
While strFileToConvert <> ''

' Attempt to convert the file to PDF
If (ConvertFile(strFolder + strFileToConvert) = False) Then
' Hmmm, looks like something went wrong - let's prompt the
user to see if they wish to quit
If (MsgBox('There has been a problem converting the file ' +

strFileToConvert + chr(13) + 'Do you wish to exit', vbYesNo) = vbYes) Then
' Finish up - let's get out of here
Exit Sub
End If
End If

' Grab the next file
strFileToConvert = Dir

End Sub


You May Also Like

About the Author: Planet PDF Team

Leave a Reply