Print a PDF file using VBA
Print a PDF file using VBA
(OP)
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'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.
RE: Print a PDF file using VBA
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
RE: Print a PDF file using VBA
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
DoNotSetAsSysDefault:=1
and to select the paper tray:
CODE
.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
RE: Print a PDF file using VBA
http://www.planetpdf.com/forumarchive/66844.asp
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)