×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Print a PDF file using VBA

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.

RE: Print a PDF file using VBA

(OP)
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

RE: Print a PDF file using VBA

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

RE: Print a PDF file using VBA

(OP)
modify the code at this link.

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)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close