IAC – Printing every PDF in a folder

This method prints all of the PDFs in the folder c:acrobatdocstoprint.

This code sample is posted here for the general benefit of the PDF development community. Attribution and usage guidelines are as noted in the code source; please respect the wishes of the author when using this code.



Option Explicit ' Force variable declaration
' Author : Planet PDF
' Date : 08 March 1998
' Description: PrintAllAcrobatDocsInDir
' This vb method uses IAC to print all documents in a
' directory.
' This method / function should be extended to suit the requirements
' of an organisation

Public Const POSTSCRIPT_LEVEL = 2
Public Const PDF_WILDCARD = '*.pdf'
Public Const PDF_DIRECTORY = 'c:acrobatdocstoprint'

Sub PrintAllAcrobatDocsInDir()
Dim AcroExchAVDoc As Object, AcroExchPDDoc As Object, _
AcroExchApp As Object
Dim strFileName As String, strPath As String
Dim iNumberOfPages As Integer
Set AcroExchApp = CreateObject('AcroExch.App')
Set AcroExchAVDoc = CreateObject('AcroExch.AVDoc')
Set AcroExchPDDoc = CreateObject('AcroExch.PDDoc')

' Show the Acrobat Exchange window
AcroExchApp.Show

' Set the directory / folder to use
strPath = PDF_DIRECTORY

' Get the first pdf file in the directory
strFileName = Dir(strPath + PDF_WILDCARD, vbNormal)

' Start the loop.
Do While strFileName <> ''

' Open the [strFileName] pdf file
AcroExchAVDoc.Open strPath + strFileName, ''
' Get the PDDoc associated with the open AVDoc

Set AcroExchPDDoc = AcroExchAVDoc.GetPDDoc

' Get the number of pages for this pdf [and subtract one as zero based]
iNumberOfPages = AcroExchPDDoc.GetNumPages - 1

' Print all pages in this document
AcroExchAVDoc.PrintPages 0, iNumberOfPages, POSTSCRIPT_LEVEL, True, False

' Close this file
AcroExchAVDoc.Close True

' Get the name of the next file in the directory
strFileName = Dir
Loop

' Close Acrobat Exchange
AcroExchApp.Exit
End Sub

You May Also Like

About the Author: Planet PDF Team

Leave a Reply