Batch print PDF files from VB

I want to be able to silently print batch pdf files from VB using user's default printer.
Using shell "AcroRd32 -p " command opens up print dialog that I don't need, and it can print only one pdf.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Have you using ShellExecute API to print? If you add a FilelistBox you can loop through it printing each document:

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub Form_Load()
File1.Pattern = "*.pdf"
File1.Path = "C:\Somefolder"
End Sub

Private Sub Command1_Click()
Dim i As Integer
For i = 0 To File1.ListCount - 1
    Call ShellExecute(hwnd, "Print", (File1.Path & "\" & File1.List(i)), "", "", 0)
Next i
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richie_SimonettiIT OperationsCommented:
I did a little example here:
What you need to avoid dialog box is using /T modifier instead of p.
Richie_SimonettiIT OperationsCommented:
hi, any progress on this? some feedback would be nice.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

bagirexAuthor Commented:
I am using WIN2K, Vb6, Acrobat 6.0
Sorry about being late on this.

Thanks, it is working except Acrobat window is left open.
How to close it?
Will it work on other that WIN platforms?


in modmain
    ' Please check that caption of acrobat is correct,
    ' otherwise this loop will never ends.
    l = FindWindow(vbNullString, "Acrobat Reader - [" & filename & "]")
Loop While l = 0

When I've commented out all but
ShellExecute 0, "print", "C:\Program Files\Adobe\Acrobat 6.0\Reader\Acrord32.exe /t " & filename, vbNullString, vbNullString, vbHide
it didn't work either.

It kept looping.
bagirexAuthor Commented:

Just read
    ' Please check that caption of acrobat is correct,
comment more carefully. Is it good idea to find acrobat instance by it's window title?
Might be differet with different versions.
Richie_SimonettiIT OperationsCommented:
Of course, you could do that way:
classname for acrobat is (at least 5.0) is:
Afx:400000:8: 10011:0:a510219
Richie_SimonettiIT OperationsCommented:
by the way, i misread your comment, it IS searching by its window title.
bagirexAuthor Commented:
At least the good news is Acrobat Reader allows only one running instance.
Afx:400000:8: 10011:0:a510219 for classname didn't work. Mine is Adobe 6.0
Richie_SimonettiIT OperationsCommented:
Well, if classname doesn't works, we have to moveback to findwindow api.
Please, check how acrobat show its caption with version 6.0
Richie_SimonettiIT OperationsCommented:
Classname for version 6.0.0 in "AdobeAcrobat"
Richie_SimonettiIT OperationsCommented:
Well, since only one instance is allowed, use code from vinnyd, just replace p modifier with t modifier.
Maybe you could call shellexecute with full path to acrobat exe only the first time and others calls to print other docs should use " /t " & filename as lpFile parameter (just a guess)
bagirexAuthor Commented:

1.  How do you find out classname for Adobe versions? I checked my registry and couldn't find it
2. Vinnyd doesn't use any modifier. It uses only 'print' , which doesn't have modifiers!?

Richie_SimonettiIT OperationsCommented:
1) there is a tool that comes with Visual studio called Spy, you could use it to know the class name from every window. Just moving the cursor over it.
2) Modifiers were hard to find for me but, as long as i know, using T as modifier, it doesn't shows you dialog box.
Richie_SimonettiIT OperationsCommented:
Hi, any progress on this?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.