# How to set default printer in PDF and print PDF one page at a time



## wango (Nov 14, 2001)

How to set default printer in PDF and print PDF one page at a time

The code below will print a PDF file to a tiff converter driver "PEERNET.DRV ePro 5.0" but I am prompted for a filename (a TIFF file) to print to.
I can only do this after setting "PEERNET.DRV ePro 5.0" as the default printer through the printer panel.

What I want is to be able to set the default printer programmatically, print all pdf file pages to individual TIFF pages (with individual names of course).

Lastly, reset the printer back to the original default printer.

(what is not declared here should be considered to be global)
Private Function GetImageFromPdf(strDirName As String, _
astrDestFolderName As String, _
astrFileName As String, _
strFileNameStem As String, _
imageType As String)

Dim fileFullPath As String

Dim AcroExchAVDoc As Object, AcroExchPDDoc As Object, _
AcroExchApp As Object

'Dim fileFullPath As String ', strPath As String
Dim iNumberOfPages As Integer

On Error GoTo HandleError

Set AcroExchApp = CreateObject("AcroExch.App")
Set AcroExchAVDoc = CreateObject("AcroExch.AVDoc")
Set AcroExchPDDoc = CreateObject("AcroExch.PDDoc")

' must restore remed out for debugging multiselect
' when we open the file it will return true/false
fileFullPath = strDirName & "\" & astrFileName

'openResult = myPDFPageCount.Open(fileFullPath)

' Open the [strFileName] pdf file
' AcroExchAVDoc.Open strPath + strFileName, ""
AcroExchAVDoc.Open fileFullPath, ""

' Get the PDDoc associated with the open AVDoc
Set AcroExchPDDoc = AcroExchAVDoc.GetPDDoc

'SavePrinter = App.ActivePrinter ' works for MS Wordl for windows
' vbPRPSLegal is a constant for 8 1/2 x 14 in legal size
Printer.PaperSize = vbPRPSLegal

'AcroExch.avdoc.PrintPages 0, pddoc.GetNumPages - 1, 1, False, False

AcroExchApp.ActivePrinter = "PEERNET.DRV ePro 5.0"  BBBOOOOOMBS

'Note The first page in a document is page 0 for OLE automation.
' from http://csis.pace.edu/~anderson/AIS/art1.html
For pagenumber = 0 To pageCount - 1

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

DoEvents
Next

' Close this file
AcroExchAVDoc.Close True

End Function


----------

