Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print a PDF file using VBA

Status
Not open for further replies.

msstrang

Programmer
Sep 19, 2005
62
US
Hello all...

I've written a program that let's the user select files within a folder and automatically print them. Where I am having trouble at is getting the program to print PDF files. Below is the code I am using:


'**********************************************************
Public Function AcrobatPrint()

Dim Acroapp As CAcroApp
Dim avCodeFile As CAcroAVDoc
Dim avFormCapture As CAcroAVDoc
Dim pdCodeFile As CAcroPDDoc
Dim pdFormCapture As CAcroPDDoc
Dim lngPage As Long
Dim AVPage As CAcroAVPageView
Dim PDPage As CAcroPDPage

filey = "*file location*"*place the location of the file in between the quotes, for debugging purposes only

Set Acroapp = CreateObject("AcroExch.App")
Acroapp.Show

Set avCodeFile = CreateObject("AcroExch.AVDoc") 'This is the code file

avCodeFile.Open filey, "tempfile"


avCodeFile.PrintPages 1, 1, 1, 1, 1

End Function
***********************************************************

I know that the values I have to the right of "avCodeFile.PrintPages" are incorrect, because everytime i run the program when it hits this line of code the "data" light on the front of my printer blinks twice and then nothing happens.

Does anyone know more about printing PDF files using VBA?

Thanks much in advance.
 
i figured it out.
in case anybody else needs help with this in the future, here is my code.

Public Sub AcrobatPrint()
Dim AcroExchApp As Acrobat.CAcroApp
Dim AcroExchAVDoc As Acrobat.CAcroAVDoc
Dim AcroExchPDDoc As Acrobat.CAcroPDDoc
Dim num As Integer

filey = "*your full file name including directory here*"
Set AcroExchApp = CreateObject("AcroExch.App")
Set AcroExchAVDoc = CreateObject("AcroExch.AVDoc")
' Open the [strfiley] pdf file
AcroExchAVDoc.Open filey, ""
' 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]
num = AcroExchPDDoc.GetNumPages - 1
Call AcroExchAVDoc.PrintPages(0, num, 1, True, True)
'AcroExchApp.Show 'activate this line if you want to see the acrobat file
AcroExchApp.Exit
AcroExchAVDoc.Close (True)
AcroExchPDDoc.Close
End Sub
 
Hey msstrang.

I'd like to create a little app, similar to yours. It would print just one of 4 .pdf files, and print it out of a specific printer, out of a particular paper tray.

I'm very new to this, so even just a pointer in the right direction (websites etc...) so I can research this further would be a great help.

In word, to select the printer, I would use:
Code:
Application.WordBasic.FilePrintSetup Printer:="\\servername\printername on printerport", _
    DoNotSetAsSysDefault:=1

and to select the paper tray:
Code:
    With ActiveDocument.PageSetup
        .FirstPageTray = wdPrinterLowerBin
        .OtherPagesTray = wdPrinterLowerBin
    End With

How would this be changed to work with Acrobat Reader?

Also, how could I create a pop-up window with a Drop-Down box so the user can select which .pdf file to print?

And, type in number of copies to be printed.

Any advice would be great.

Thanks

keV
 
modify the code at this link.


try using an input box to get the user to enter the number of pages they wish to print:

CopiesPages= InputBox ("Please enter the number of copies you want to print")
Call AcroExchAVDoc.PrintPages(0,num, CopiesPages, True, True)

To select your files from a list, use the code below:
Dim filex As Variant
filex = Application.GetOpenFilename _
(FileFilter:="Acrobat Files (*.pdf), *.pdf", _
Title:="Get Files to Print", MultiSelect:=True)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top